如何使用SourceTree将本地repo推送到Bitbucket,而无需首先在bitbucket上创建回购? [英] How do I push a local repo to Bitbucket using SourceTree without creating a repo on bitbucket first?

查看:239
本文介绍了如何使用SourceTree将本地repo推送到Bitbucket,而无需首先在bitbucket上创建回购?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将我的本地git仓库导入SourceTree,并将它们推送到我的Bitbucket账户,在我的账户中创建与本地仓库相同的新仓位?或者我必须首先在线制作回购网站并推向该网站? Github有一种方法可以直接从客户端发布本地回购协议,并且在发布时自动创建它,但它的私人回购数量有限。我只是在做功课,所以没有理由让它公开,因此我试图使用bitbucket。 解决方案

似乎可以将本地存储库发布到BitBucket。使用 Atlassian 中的说明,只需创建一个新的BitBucket存储库,将(在你的BitBucket仓库中,进入Actions> Clone,它会以 git clone< repository url> 的形式显示你的repo url) ,然后将该存储库添加为本地存储库的新远程设备:

使用CLI


  1. cd / path / to / my / repo

  2. git remote add origin ssh://git@bitbucket.org/< username> /< reponame> .git

  3. git push -u origin -all

使用SourceTree


  1. 存储库>添加远程...

  2. 粘贴BitBucket存储库URL( git @ bitbucket.org/<username> /< reponame> .git



UPDATE:Creating&a熔点;注册SSH密钥



BitBucket非常适合私人回购,但您需要设置一个ssh密钥来授权您的计算机使用BitBucket帐户。幸运的是,Sourcetree使它变得相对简单:



在SourceTree中创建密钥


  1. 工具> 选项中,确保 SSH客户端:常规选项卡下设置为 PuTTY / Plink
  2. 选择工具> 创建或导入SSH密钥

  3. 弹出窗口,点击生成,然后移动鼠标以给密钥生成器赋予随机性。
  4. 你应该得到类似于whats如下面的屏幕截图所示。将公钥(蓝色高亮)复制到剪贴板中

    putty>


  5. 点击保存私钥保存公钥< code>< Home Dir> /putty/ssk-key.ppk 和< Home Dir> /putty/ssh-key.pub ),然后再转到下一部分

在BitBucket中注册密钥


  1. 登录到您的 BitBucket 帐户,然后点击右上角的个人资料图片并点击设置

  2. 转到左边栏上的 SSH密钥选项卡

  3. 单击添加SSH密钥,给它一个名字,然后粘贴你在上一节的第4步中复制的公钥

就是这样!你现在应该可以推/拉你的BitBucket私人回购。你的密钥不仅仅适用于Git,许多服务使用ssh密钥来识别用户,最好的部分是你只需要一个。如果您丢失了密钥(例如,在更换计算机时),请按照以下步骤创建并注册一个新密钥。



Sidenote:使用CLI创建SSH密钥



只要按照这个教程


Is there a way to import my local git repos to SourceTree and push them to my Bitbucket account, having new repos identical to my local repos be created on my account? Or do I have to make a repo online first and push to that? Github has a way to publish your local repos directly from it's client, and it creates it automatically when you publish, but it has limited private repos. I'm just doing homework so there's no reason for it to be public, hence why I'm trying to use bitbucket.

解决方案

It does seem possible to "publish" a local repository to BitBucket. Using the instructions from Atlassian, simply create a new BitBucket repository, copy the repository url to the clipboard (in your BitBucket repository, go to Actions>Clone, and it'll show you your repo url in the form git clone <repository url>), and then add that repository as a new remote to your local repository:

Using CLI

  1. cd /path/to/my/repo
  2. git remote add origin ssh://git@bitbucket.org/<username>/<reponame>.git
  3. git push -u origin --all

Using SourceTree

  1. Repository>Add Remote...
  2. Paste the BitBucket repository url (git@bitbucket.org/<username>/<reponame>.git)

UPDATE: Creating & Registering SSH Keys

BitBucket is great for private repos, but you'll need to set up an ssh key to authorize your computer to work with your BitBucket account. Luckily Sourcetree makes it relatively simple:

Creating a Key In SourceTree:

  1. In Tools>Options, make sure SSH Client: is set to PuTTY/Plink under the General tab
  2. Select Tools>Create or Import SSH Keys
  3. In the popup window, click Generate and move your mouse around to give randomness to the key generator
  4. You should get something like whats shown in the screenshot below. Copy the public key (highlighted in blue) to your clipboard

  5. Click Save private Key and Save public key to save your keys to wherever you choose (e.g. to <Home Dir>/putty/ssk-key.ppk and <Home Dir>/putty/ssh-key.pub respectively) before moving on to the next section

Registering The Key In BitBucket

  1. Log in to your BitBucket account, and on the top right, click your profile picture and click Settings
  2. Go to the SSH Keys tab on the left sidebar
  3. Click Add SSH Key, give it a name, and paste the public key you copied in step 4 of the previous section

That's it! You should now be able to push/pull to your BitBucket private repos. Your keys aren't just for Git either, many services use ssh keys to identify users, and the best part is you only need one. If you ever lose your keys (e.g. when changing computers), just follow the steps to create and register a new one.

Sidenote: Creating SSH Keys using CLI

Just follow this tutorial

这篇关于如何使用SourceTree将本地repo推送到Bitbucket,而无需首先在bitbucket上创建回购?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆