如何使用SourceTree将本地repo推送到Bitbucket,而无需首先在bitbucket上创建回购? [英] How do I push a local repo to Bitbucket using SourceTree without creating a repo on bitbucket first?
问题描述
有没有办法将我的本地git仓库导入SourceTree,并将它们推送到我的Bitbucket账户,在我的账户中创建与本地仓库相同的新仓位?或者我必须首先在线制作回购网站并推向该网站? Github有一种方法可以直接从客户端发布本地回购协议,并且在发布时自动创建它,但它的私人回购数量有限。我只是在做功课,所以没有理由让它公开,因此我试图使用bitbucket。 解决方案
似乎可以将本地存储库发布到BitBucket。使用 Atlassian 中的说明,只需创建一个新的BitBucket存储库,将(在你的BitBucket仓库中,进入Actions> Clone,它会以 git clone< repository url>
的形式显示你的repo url) ,然后将该存储库添加为本地存储库的新远程设备:
使用CLI
-
cd / path / to / my / repo
-
git remote add origin ssh://git@bitbucket.org/< username> /< reponame> .git
-
git push -u origin -all
使用SourceTree
- 存储库>添加远程...
- 粘贴BitBucket存储库URL(
git @ bitbucket.org/<username> /< reponame> .git
)
UPDATE:Creating&a熔点;注册SSH密钥
BitBucket非常适合私人回购,但您需要设置一个ssh密钥来授权您的计算机使用BitBucket帐户。幸运的是,Sourcetree使它变得相对简单:
在SourceTree中创建密钥:
- 在
工具
>选项
中,确保SSH客户端:
在常规
选项卡下设置为PuTTY / Plink
- 选择
工具
>创建或导入SSH密钥
- 弹出窗口,点击
生成
,然后移动鼠标以给密钥生成器赋予随机性。
-
你应该得到类似于whats如下面的屏幕截图所示。将公钥(蓝色高亮)复制到剪贴板中
putty> - 点击
保存私钥
和保存公钥
< code>< Home Dir> /putty/ssk-key.ppk 和< Home Dir> /putty/ssh-key.pub
),然后再转到下一部分
在BitBucket中注册密钥
- 登录到您的 BitBucket 帐户,然后点击右上角的个人资料图片并点击
设置
- 转到左边栏上的
SSH密钥
选项卡 - 单击
添加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
cd /path/to/my/repo
git remote add origin ssh://git@bitbucket.org/<username>/<reponame>.git
git push -u origin --all
Using SourceTree
- Repository>Add Remote...
- 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:
- In
Tools
>Options
, make sureSSH Client:
is set toPuTTY/Plink
under theGeneral
tab - Select
Tools
>Create or Import SSH Keys
- In the popup window, click
Generate
and move your mouse around to give randomness to the key generator You should get something like whats shown in the screenshot below. Copy the public key (highlighted in blue) to your clipboard
- Click
Save private Key
andSave 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
- Log in to your BitBucket account, and on the top right, click your profile picture and click
Settings
- Go to the
SSH Keys
tab on the left sidebar - 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
这篇关于如何使用SourceTree将本地repo推送到Bitbucket,而无需首先在bitbucket上创建回购?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!