Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Git] 使用不同账号将本地内容推送到 Github #20

Open
yangruihan opened this issue Nov 21, 2020 · 1 comment
Open

[Git] 使用不同账号将本地内容推送到 Github #20

yangruihan opened this issue Nov 21, 2020 · 1 comment

Comments

@yangruihan
Copy link
Owner

使用不同账号将本地内容推送到 Github

问题描述

我有2个 Github 账号,在提交不同的库时,想使用不同的 Github 账号

解决方案

方式一 ssh 方式使用 config

如果仓库使用的是 ssh,切对应 Github 账号都配置了密钥,那么可以使用如下命令,对不同的仓库设置不同的用户名和邮箱地址

git config user.name her_username
git config user.email her_email

使用这种方法,会将提交日志上的用户名和邮箱也更改

如果使用的是 Https 方式,那么这种方法不适用于 Push

现在 Github 默认 clone 的方式是 Https,因此该方法有一定局限

方式二 https 方式清理密码管理器

git config --local credential.helper ""
git push origin master

macOS下需要去 Keychain Access 里删除 Github Login 项

清理密码管理器后,推送时,将会出现输入用户名和密码的提示,输入不同的用户名和密码即可

方式三 推送时附带用户名和密码

git push https://'B_user_name':'B_password'@github.com/B_user_name/project.git

参考地址

https://stackoverflow.com/questions/13103083/how-do-i-push-to-github-under-a-different-username

@CodeCloneDL
Copy link

感谢归纳,正需要这个

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants