Home  >  Q&A  >  body text

javascript - How to configure 2 git accounts on different hosts on the same computer?

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?

世界只因有你世界只因有你2684 days ago863

reply all(5)I'll reply

  • 天蓬老师

    天蓬老师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

    reply
    0
  • phpcn_u1582

    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.

    reply
    0
  • PHP中文网

    PHP中文网2017-06-14 10:51:40

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

    reply
    0
  • 習慣沉默

    習慣沉默2017-06-14 10:51:40

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

    reply
    0
  • 给我你的怀抱

    给我你的怀抱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

    reply
    0
  • Cancelreply