同一台mac管理多个git 账号/同一个项目推送到多个远程仓库

本文介绍了如何在一台Mac上同时管理公司和个人的git账号,解决推送项目到不同远程仓库时权限问题。通过生成和配置不同的SSH密钥,以及编辑~/.ssh/config文件,确保每个项目对应正确的SSH密钥。此外,还解决了同一项目推送到公司git和码云仓库时遇到的问题,包括偶尔的推送失败,以及无需每次都执行ssh-add的临时解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题1:一台电脑绑定两个git账号,描述:

公司git账号:company   项目名称:CompanyApp

个人git账号:self            项目名称:SelfApp 

公司项目在push时正常,但是在个人项目push到远程时提示错误:

zww:SelfApp mac$ git push -u origin master
ERROR: Permission to self/SelfApp.git denied to company.
fatal: Could not read from remote repository.


Please make sure you have the correct access rights

或者个人项目push正常时,公司项目push出现

zww:CompanyApp mac$ git push -u origin master
ERROR: Permission to company/CompanyApp.git denied to self.
fatal: Could not read from remote repository.


Please make sure you have the correct access rights

因为github是使用SSH key的fingerprint来判定你是哪个账户,而不是通过用户名。这种情况下github无法判断使用哪个.ssh/id_rsa.pub所对应的账户进行登陆。

解决方法:

第一步:配置SSH-Key:

1.生成对应公司和个人git账号的rsa,rsa.pub文件

ssh-keygen -t rsa -C "xxxxx@xxxxx.com"

#这里为了方便区分改变id_rsa文件名字:

Enter file in which to save the key (/Users/mac/.ssh/id_rsa): /Users/mac/.ssh/company_id_rsa  

#两次回车即密码设置为空

Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值