1. 多账号切换

比如你想用A账号管理本地仓库repoA,用B账号管理本地仓库repoB。
那么首先,看一下gloabal和system的config:

  1. $ git config --global -l
  2. $ git config --system -l

主要是看有没有credential.helper把账号密码存起来了。因为https的url方式每次push的时候都要输入密码,比较麻烦,一般就会用credential.helper把账号密码存在global里了。这样对单用户没问题,但多用户时就会有问题。如果存的是A账户,那在repoB里push的时候肯定就会permission denied。所以看看global或者system哪个设置了保存就unset一下:

  1. $ git config --global --unset credential.helper
  2. $ git config --system --unset credential.helper

切换远程仓库的地址

  1. $ git remote -v
  2. $ git remote set-url origin https://UserA@github.com/UserA/repoA.git

可以将远程仓库地址换为其他的远程仓库或是改用 ssh 登录.

2.修改提交作者和邮箱

设置全局(不利于多账号设置, 不应使用)

  1. $ git config --global user.name "Author Name"
  2. $ git config --global user.email "Author Email"

设置本地项目库

  1. $ git config user.name "Author Name"
  2. $ git config user.email "Author Email"

参考资料:
https://www.zhihu.com/question/23028445
https://blog.csdn.net/diu_brother/article/details/51982993