gpt4 book ai didi

git - 多个 bitbucket 帐户

转载 作者:IT王子 更新时间:2023-10-29 00:34:52 26 4
gpt4 key购买 nike

我的朝九晚五工作有一个 Bitbucket 帐户,我还有一个个人 Bitbucket 帐户。我的目标是能够在同一台计算机上同时使用两者。我已经在 Windows 7 电脑上安装了最新的 git。

因此,目前我公司 Bitbucket 帐户的一切工作正常,我可以毫无问题地 pull/推。我使用 ssh-keygen 创建了一个新的 ssh key ,并在我的案例中分配了一个新名称“tech”。但是我在如何告诉本地仓库使用我创建的新 ssh key 方面遇到了问题。我假设每次我尝试连接它时都使用第一个 ssh key 。

我得到错误:

$ 推送conq:存储库访问被拒绝。fatal: 远端意外挂断

我在互联网上找到了一些建议,但它似乎与 linux/git 设置有关,例如我在 Windows 上找不到“配置”文件。

最佳答案

This blog post描述了一种将多个 ssh key 添加到一台计算机并为每个 bitbucket 帐户使用一个 ssh key 的直接方法。它比 official bitbucket documentation 清楚得多.总结:

首先,确保您已通过类似 this one on Github 的教程设置了默认帐户。 .

对于第二个帐户:

  1. 创建一个新的 ssh key :

    ssh-keygen -f ~/.ssh/<your second account name> -C "<you email>"
  2. 添加 ssh key :

    ssh-add ~/.ssh/<key file name> 
  3. 使用 pbcopy < ~/.ssh/<your second account name>.pub复制公钥并将此 key 添加到您的 bitbucket 帐户(在设置区域)

(在 Windows 上,您可以使用 ssh-keygen -f ~/.ssh/<your account name> -c "<your email>" | clip Linux you can follow these instructions. 复制 ssh key )

  1. 将以下内容添加到您的 ~/.ssh/config文件。第一个设置 bitbucket.org 的默认 key 。第二个将您的第二个 key 设置为别名 bitbucket-account2对于 bitbucket.org:

    Host bitbucket.org
    Hostname bitbucket.org
    IdentityFile ~/.ssh/id_rsa

    Host bitbucket-account2
    Hostname bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/<your second account name>
  2. 您现在可以像以前一样使用默认帐户克隆项目:

    git clone git@bitbucket.org:username/project.git
  3. 要使用第二个身份克隆项目,请将 bitbucket.org 替换为您在 ~/.ssh/config 中指定的主机。文件(即上面的 bitbucket-account2):

    git clone git@bitbucket-account2:username/project.git

就是这样!

关于git - 多个 bitbucket 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8186441/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com