Search code examples
gitgithubversion-controlgitlabbitbucket

How to switch git email based on host?


I have accounts in three different Git service providers - GitHub, GitLab and BitBucket. I want to ensure that my commits are signed via SSH in all of the mentioned providers, which is not possible since I have assigned a GitLab email at the moment, and all of my accounts use unique emails. This only verifies signed commits for GitLab successfully. How do I make it so that GitHub/BitBucket repositories will be assigned to their respective email?

Haven't found anything online that deals with this. There is a "gitdir" method, but I am not looking for this. I am expecting that Git understands what host I am using (if on GitHub, use [email protected], if on GitLab, use [email protected] and so on), and based on that, assign emails.


Solution

  • Git allows you to set the default email address for new commits in a local repository clone via the following command:

    $ git config --local user.email "[email protected]"
    

    So as long as any given local repository of yours is only pushing to a given hosting service, then you should be able to assign the appropriate email to the commits.

    Does that answer your question?