Gitconfig

splitting the config

Gitconfig is a interesting file when you are able to use an if statement based on the directory of a project. Below is my tree for projects that both define personal and professional configurations. This allows me

/Users/addlema
├── .sh.d
├── src
│   ├── git.worksite.com
│   └── github.com
├── .gitconfig
├── .gitconfig-personal
├── .gitconfig-work

In my $HOME/.gitconfig file I have the following:

[includeIf "gitdir:~/src/github.com/"]
	path = .gitconfig-personal
[includeIf "gitdir:~/src/git.worksite.com/"]
	path = .gitconfig-work

Then in my $HOME/.gitconfig-personal, I use the following content:

[user]
name = Aaron Addleman
email = [email protected]
signingkey = FCF6C3A2140015F9

[commit]
gpgSign = true

The other file of $HOME/.gitconfig-work shares the same name, but a different email address. This helps automatically set the Name and Email settings for git projects based on the top level directory they reside within.

aliases

Sometimes its needed to have some handy aliases to do git actions. Two of them I have been using is the reset from origin and reset from upstream:

[alias]
resetorigin = !git fetch origin && git reset --hard origin/${1-main} && git clean -f -d
resetupstream = !git fetch upstream && git reset --hard upstream/${1-main} && git clean -f -d
Previous