There are several ‘levels’ at which you can configure git. The three I know about are:
- repository branch-level
They are slightly self explanatory.
- repository branch-level means that the configurations/aliases are applied ONLY to a specific branch in that repository. I haven’t had a need to use this one yet, so I can’t tell you a ton about it.
- repository-level means that the configurations/aliases are applied ONLY to that repository, but to all branches on that repository. This can be configured to use different email addresses to different projects (ex: work email vs personal email), among other things.
- global means that the configurations/aliases are applied to ALL git repositories on your system.
So, how do we set this up?
From the command line
Most of the tutorials on how to set up aliases give the command line version.
In your git repository, you can type
git config XXX (where XXX is filler for whatever configuration you want to set). To set the configurations globally, you can type
git config --global XXX. Adding the
--global flag sets it for all git repositories. Some examples:
git config --global user.name "Clare Glinka"
– This sets my name as “Clare Glinka” for all repos.
git config --global user.email email@example.com
– This sets my email as firstname.lastname@example.org for all repos.
git config merge.ff false
– disables fast-forward merges by default at the repository level. Fast-forward merging will be disabled for all branches in that repo. Adding the
--global flag will disable fast-forward merging for ALL repos.
Now that we’ve set some configs, how do we look at them? (because nothing is real till we see the output, right?)
git config --list will list all the configuration settings for your current directory/branch, including things like your remotes.
git config --list --global will list all the configurations settings for your system. For me, this is a much shorter list, since it does not include things like remotes.
There is another way to set configurations that I find a little easier to look at sometimes. That is checking out the
.gitconfig file. For your global settings,
.gitconfig lives in your
~ directory, and you can open it up and edit it with your favorite text editor. You can check out your repository-level configuration file by looking at
First-Time Git Setup
Customizing Git Configuration
git-config Manual Page
StackOverflow: Can I make fast forwarding be off by default in git?
Git Tip: git config user name and email for local (not global) config