如何在同一台电脑上使用不同的git账号

Git
作者

yangjh

发布日期

2023年7月7日

通常情况下,我们使用全局性配置,使用 Git 工具进行版本管理:

git config --global [user.name](http://user.name) "xxx"
git config --global user.email "xxxx" 

但是,上述设置在同一台电脑上需要使用多个账户进行git仓库管理的时候,会出现账号冲突的问题。因此,我们需要使用如下措施:

在仓库中使用本地配置,这样就可以在不同的仓库中,使用不同于全局设置的用户进行操作:

git config [user.name](http://user.name) "xxx"
git config user.email "xxxx" 

除此之外,在 Windows 10 中,我们可能还需要进行对仓库的配置进行修改,打开仓库中.git目录中的config文件,在其中远程仓库的信息中直接写入用户名:

url = https://username@gitee.com/username/repos.git

如果在远程仓库信息中不写入具体用户名称,在 Windows 10 中进行推送操作是就会使用已有用户的凭据信息进行操作,出现仓库操作权限问题。例如:

remote: You do not have permission push to this repository

参考文献

git帮助文件doc/git-doc/git-push.html中的

>
> * ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
 * [user@]host.xz:/~[user]/path/to/repo.git/ 
回到顶部