How does GitHub know which account I am using?

前端 未结 2 1591
感情败类
感情败类 2021-01-19 23:42

I have two GitHub accounts, one is for my work and the other is for my personal use. I want to keep these two separate when I\'m doing commits.

Currently, I simply c

相关标签:
2条回答
  • 2021-01-19 23:51

    1)

    Github recognize you from your ssh public key. If you didn't submit a public key, github will ask you for your account name and password when you are trying to push code. Check your 'settings -> SSH and GPG keys -> SSH key' in your github profile.

    git config --global user.name "myusername"
    git config --global user.email [myemail]
    

    The git config content just tell other people what name you want to be called and what email you want to be sent. In fact, you can even leave them blank or fill in any contents.

    git config --global user.name "what ever"
    git config --global user.email anyone@anysite.any
    

    2)

    You can try to use different ssh keys. Or simply, you can use different email and name in your .git/config

    personal:

    [user]
        name = your honey
        email = xxx+personal@gmail.com
    

    work:

    [user]
        name = your reliable employee
        email = xxx+work@gmail.com
    
    0 讨论(0)
  • 2021-01-20 00:04

    If I change my git user/email to my personal account in my work repo and made a commit, will that commit be successful and go through to github?

    Yes, but it will be attributed to the wrong email address. See Github help:

    If your commits are not linked to any user, we will display the grey Octocat logo beside them

    Each commit in git is tagged with an email address. This can be any email address you'd like, as far as GitHub is concerned.

    This answer goes over ways to quickly switch between accounts locally. I like the idea of updating the .git/config file in the .git directory of each repo that tells git which email to use:

    [user]
        name = John Doe
        email = email@email.com
    

    Add that to the .git/config file for each repository you're working on and git will attribute your commits based on the per-repository email.

    If you're wondering how Github keeps track of all this, it is done through something called email aliases.

    0 讨论(0)
提交回复
热议问题