Skip to content

Instantly share code, notes, and snippets.

@mgaebler
Last active January 31, 2022 15:50
Show Gist options
  • Save mgaebler/0f0a027fa725da3b4b23a8e4895ff54f to your computer and use it in GitHub Desktop.
Save mgaebler/0f0a027fa725da3b4b23a8e4895ff54f to your computer and use it in GitHub Desktop.
Pro Git

Git supports conditional includes since version 2.13. With these you're able to allow overrides under specific conditions. Sometimes it's useful to separate configurations, because your company uses different git settings like email or ssh key.

I've organised my projects in different directories, private and work.

~/
├── private
└── work

I add a config file in my work directory, which will override my global git settings, with my work settings.

# ~/projects/work/.gitconfig
[user]
    email = marian.gaebler@protofy.com
[core]
    sshCommand = "ssh -i /Users/mariangaebler/.ssh/protofy_rsa"

Go to your global git config and add the following line ~/.gitconfig.

...
[includeIf "gitdir:~/projects/work/**"]
    path = /Users/mariangaebler/projects/work/.gitconfig

Finaly you have to initialize git in your work-folder.

git init

And we're done.

You can test your settings with git config -l or git config user.email. The correct value should be outputted.

Helpful git commands

Switch back to latest used branch

git switch -

Update origin branches without changing to their local equivalents

This pushes the origin main branch to the stage branch. Don't forget to push main first to origin.

git push origin main:stage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment