Quantcast
Channel: Shortcuts – info.michael-simons.eu
Viewing all articles
Browse latest Browse all 10

Use different Git usernames and emails for work and play

$
0
0

A bit hidden away in the release notes of Git 2.13 but found by my friend Michael Vitz from INNOQ is the not so new anymore feature of conditional configuration respectively conditional includes.

Git has several levels of configuration: System wide, per user, per repository and finally, on each individual command invocation. If a values is defined on several levels, the most specific counts.

Configuration files can include other files with include and includeIf. The included files behave as if the configuration they contain had been written in the including file.

includeIf includes files conditionally. Right now, it only supports one attribute, gitdir: “The data that follows the keyword gitdir: is used as a glob pattern. If the location of the .git directory matches the pattern, the include condition is met.”

Depending on the directory your repo is in, you can pull in different configuration files. That comes in very handy to configure different a different username and email address, for example to differentiate between work and play (taken directly from the release notes):

Put this into your user specific .gitconfig:

[includeIf "gitdir:~/work/"]
  path = .gitconfig-work
[includeIf "gitdir:~/play/"]
  path = .gitconfig-play

And create additional .gitconfig-work and .gitconfig-play (the files can reside wherever you want, you can use a full path as well:

[user]
name = Serious Q. Programmer
email = serious.programmer@business.example.com
[user]
name = Random J. Hacker
email = rmsfan1979@example.com

Read more about git-config includes and fine more usage examples in the official documentation. I curate a list of some more or less useful git snippets here.

Did you like this article? You can invite me on a coffee ☕ if you like.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images