栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

本地git配置不同的bitbucket账号仓库

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

本地git配置不同的bitbucket账号仓库

文章目录
  • bitbucket account
  • 本地git配置不同的bitbucket账号仓库
    • 方法:
    • 步骤
      • 在本地C:/user/.ssh/中,生成公钥和私钥,新建config文件
      • 在Bitbucket账号内,添加SSH公钥
      • 在./ssh目录下测试ssh-key是否连通:
      • 在local repository下,进行git配置
      • git clone怎么办

bitbucket account
bitbucket accountemail
locallocal@email.com
companycompany@email.com
本地git配置不同的bitbucket账号仓库 方法:

在~./ssh/下各自生成不同的密钥和公钥,再对应到各自账号的bitbucket/settings/SSH keys下。

在不同的本地仓库下配置git config和 remote url。

步骤 在本地C:/user/.ssh/中,生成公钥和私钥,新建config文件
  1. 进入:/user/.ssh/,open git bash
  2. 生成公钥和私钥:

ssh-keygen -t rsa -f id_rsa_local一路回车,

ssh-keygen -t rsa -f id_rsa_company一路回车
3. 将私钥配置到本地git上

ssh-agent bash

ssh-add id_rsa_local

ssh-add id_rsa_company

ssh-add -l查看私钥添加结果
4. 创建并配置config文件(非文本文件)
.ssh目录下创建config文件,git通过该文件确定对应的私钥和公钥
config文件内容:

# local
Host local
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa_local
 
# company
Host company
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa_company
 
在Bitbucket账号内,添加SSH公钥
1. 进入bitbucket 的local账号,进入Personal Setting-> SSH Keys-> Add SSH Keys,添加复制id_rsa_local.pub公钥内容;
2. 进入bitbucket 的company 账号,进入Personal Setting-> SSH Keys-> Add SSH Keys,添加复制id_rsa_company.pub公钥内容;
在./ssh目录下测试ssh-key是否连通:
ssh -T git@local
authenticated via ssh key.
You can use git to connect to Bitbucket. Shell access is disabled

ssh -T git@company
authenticated via ssh key.
You can use git to connect to Bitbucket. Shell access is disabled

此时公钥和私钥都配置正确了。

在local repository下,进行git配置
  1. 进入D:/local repository/,open git bash
  2. git config user.name "local"
  3. git config user.email "lcoal@email.com"
  4. git config --list 查看配置是否更新
  5. git remote rm origin 删除之前的remote
  6. git remote -v 查看
  7. git remote add origin git@local:username/repo.git
git clone怎么办

如果要git clone的话,需要使用SSH的方式clone。

SSH 的链接格式为:
git clone git@bitbucket.org:username/repo.git

修改为:

git clone git@local:username/repo.git

git clone git@company:username/repo.git

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/881964.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号