How does GitHub know which account I am using?

前端 未结 2 1611
感情败类
感情败类 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-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.

提交回复
热议问题