Maintaining multiple identities with Git

[This article was first published on cynkra, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

When committing to a Git repository related to my consulting work, it’s very important for me to use my company e-mail address, [email protected] . Not so much for my open-source work – for this I prefer other addresses, like [email protected] . (For example, Travis CI sends notification e-mails to the committer’s e-mail address, and I have set up filtering for that other address.)

illustration
Photo by Carson Arias


Configuring the e-mail address for each repository separately gets annoying very soon. Rather, I’d like all repos in a specific subdirectory to use a specific e-mail address.

All my Git repos live in ~/git. Subdirectories R and cynkra, respectively, contain R packages and repos related to consulting. To achieve the desired setup, I edit my ~/.gitconfig to contain the following entry:

[includeIf "gitdir:git/**"]
        path = git/.gitconfig
        

This makes sure that all repos that live underneath the git directory use the git/.gitconfig file in addition to the main configuration. That file contains the following:

[includeIf "gitdir:R/**"]
        path = R/.gitconfig
        [includeIf "gitdir:cynkra/**"]
        path = cynkra/.gitconfig
        

Finally, in ~/git/R/.gitconfig and ~/git/cynkra/.gitconfig, I configure the e-mail addresses I want to use for all repos underneath R and cynkra, respectively.

[user]
        email = ...
        

I verify the setup with git config -l | grep user. Indeed, cynkra repos use the cynkra e-mail address. Voilà!

This requires a recent-ish version of git, version 2.14 or later should suffice. Read more about conditional includes.

To leave a comment for the author, please follow the link and comment on their blog: cynkra.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)