Post

Using Different Email Addresses For Git Commits For Azure DevOps And GitHub

If you work with Azure DevOps and GitHub with different email addresses you may want to align your commit email addresses with the email addresses on your accounts.

We can do this automatically via ~/.gitconfig: (edit this file in your home directory or create it if it does not exist)

1
2
3
4
5
6
7
[user]
  name = Your Name
  email = YourGitHubEmail@example.com
[includeIf "hasconfig:remote.*.url:https://*dev.azure.com/**"]
  path = ~/.gitconfig-Azure-DevOps
[includeIf "hasconfig:remote.*.url:git@ssh.dev.azure.com:v3/**"]
  path = ~/.gitconfig-Azure-DevOps

Create the ~/.gitconfig-Azure-DevOps file that is linked to:

1
2
[user]
  email = YourAzureDevOpsEmail@example.com

This defaults to the GitHub email address and specifies a different email address for Azure DevOps. This should work for both HTTPS and SSH, provided the url patterns match one of the above.

This post is licensed under CC BY 4.0 by the author.