javascript - How to configure 2 git accounts on different hosts on the same computer?
世界只因有你
世界只因有你 2017-06-14 10:49:40
0
5
846

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?

世界只因有你
世界只因有你

reply all(5)
Peter_Zhu

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_u1582

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.

Ty80

http://blog.styxzp.com/2016/0...
Detailed answer

習慣沉默

You can refer to my previous article, I hope it will be a little inspiring /a/1190000008197936

给我你的怀抱

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!