I have a github account, but the company uses another account, and the company account requires configuring the user name and user email, so I set up global git config --global user.name and git config --global user.email , now I use the company account to pull and push normally, but every time I use my own account, it shows Permission denied (publickey). Then I need to manually add ssh-add ~/.ssh/id_myselfgithub every time, is there any How can I configure different accounts on the same computer?
天蓬老师2017-06-14 10:51:40
When there are multiple git accounts, you need to configure ~/.ssh/config to distinguish them. Please search for the specific configuration
Host github.com
HostName github.com
IdentityFile ~/.ssh/gh_rsa
phpcn_u15822017-06-14 10:51:40
git configures your user through the configuration file
The global configuration user you mentioned is actually adding three lines to the ~/.gitconfig file
[user]
name = vincent178
email = vincent***@gmail.com
When you clone a git repository, there is a config file in the .git folder by default to record repository-level users
So your problem can be solved by adding your user information in /path/to/repository/.git/config, the format is the same as the result of global configuration.
Then git also provides a command line method to configure, as written above.
習慣沉默2017-06-14 10:51:40
You can refer to my previous article, I hope it will be a little inspiring /a/1190000008197936
给我你的怀抱2017-06-14 10:51:40
Set the local user
in the git project using your own account and it should be fine
config config user.name xxx
config config user.email xxx
After generating the ssh public key, add it to your own git account configuration