# Setting which editor to use
There are several ways to set which editor to use for committing, rebasing, etc.
$ git config --global core.editor nano
$ GIT_EDITOR=nano git commit
Or for all commands run in a terminal. Note: This only applies until you close the terminal.
$ export GIT_EDITOR=nano
$ export EDITOR=nano
Note: As above, this only applies to the current terminal; your shell will usually have a configuration file to allow you to set it permanently. (On
bash, for example, add the above line to your
Some text editors (mostly GUI ones) will only run one instance at a time, and generally quit if you already have an instance of them open. If this is the case for your text editor, Git will print the message
Aborting commit due to empty commit message. without allowing you to edit the commit message first. If this happens to you, consult your text editor's documentation to see if it has a
--wait flag (or similar) that will make it pause until the document is closed.
# Auto correct typos
git config --global help.autocorrect 17
This enables autocorrect in git and will forgive you for your minor mistakes (e.g.
git stats instead of
git status). The parameter you supply to
help.autocorrect determines how long the system should wait, in tenths of a second, before automatically applying the autocorrected command. In the command above, 17 means that git should wait 1.7 seconds before applying the autocorrected command.
However, bigger mistakes will be considered as missing commands, so typing something like
git testingit would result in
testingit is not a git command.
# Username and email address
Right after you install Git, the first thing you should do is set your username and email address. From a shell, type:
git config --global user.name "Mr. Bean" git config --global user.email email@example.com
git configis the command to get or set options
--globalmeans that the configuration file specific to your user account will be edited
user.emailare the keys for the configuration variables;
useris the section of the configuration file.
firstname.lastname@example.org the values that you're storing in the two variables. Note the quotes around
"Mr. Bean", which are required because the value you are storing contains a space.
# Multiple git configurations
You have up to 5 sources for git configuration:
- **`%ALLUSERSPROFILE%\Git\Config`** (Windows only)
- (system) **`
/etc/gitconfig`**, with ` ` being the git installation path.
(on Windows, it is **`
- (system) **`$XDG_CONFIG_HOME/git/config`** (Linux/Mac only)
- (global) `~/.gitconfig` (Windows: `%USERPROFILE%\.gitconfig`)
- (local) `.git/config` (within a git repo `$GIT_DIR`)
- a **dedicated file** (with `git config -f`), used for instance to modify the config of submodules: `git config -f .gitmodules ...`
- The order is depended, the last one who matches "wins".
/at the end is needed - e.g.
gitdir:prefix is required.
- git config [
] name [value] # one of the more common use cases of git config
The order is important: any config set in one source can be overridden by a source listed below it.
git config --system/global/local is the command to list 3 of those sources, but only git config -l would list all resolved configs.
"resolved" means it lists only the final overridden config value.
Since git 2.8, if you want to see which config comes from which file, you type:
git config --list --show-origin
# List and edit the current configuration
Git config allows you to customize how git works. It is commonly used to set your name and email or favorite editor or how merges should be done.
To see the current configuration.
$ git config --list ... core.editor=vim credential.helper=osxkeychain ...
To edit the config:
$ git config <key> <value> $ git config core.ignorecase true
If you intend the change to be true for all your repositories, use
$ git config --global user.name "Your Name" $ git config --global user.email "Your Email" $ git config --global core.editor vi
You can list again to see your changes.
# Multiple usernames and email address
Since Git 2.13, multiple usernames and email addresses could be configured by using a folder filter.
# Example for Windows:
git config --global -e
[includeIf "gitdir:D:/work"] path = .gitconfig-work.config [includeIf "gitdir:D:/opensource/"] path = .gitconfig-opensource.config
File in the same directory as .gitconfig
[user] name = Money email = email@example.com
File in the same directory as .gitconfig
[user] name = Nice email = firstname.lastname@example.org
# Example for Linux
[includeIf "gitdir:~/work/"] path = .gitconfig-work [includeIf "gitdir:~/opensource/"] path = .gitconfig-opensource
The file content and notes under section Windows.
# Configuring line endings
When working with a team who uses different operating systems (OS) across the project, sometimes you may run into trouble when dealing with line endings.
# Microsoft Windows
When working on Microsoft Windows operating system (OS), the line endings are normally of form - carriage return + line feed (CR+LF). Opening a file which has been edited using Unix machine such as Linux or OSX may cause trouble, making it seem that text has no line endings at all. This is due to the fact that Unix systems apply different line-endings of form line feeds (LF) only.
In order to fix this you can run following instruction
git config --global core.autocrlf=true
On checkout, This instruction will ensure line-endings are configured in accordance with Microsoft Windows OS (LF -> CR+LF)
# Unix Based (Linux/OSX)
Similarly, there might be issues when the user on Unix based OS tries to read files which have been edited on Microsoft Windows OS. In order to prevent any unexpected issues run
git config --global core.autocrlf=input
On commit, this will change line-endings from CR+LF -> +LF
# configuration for one command only
you can use
-c <name>=<value> to add a configuration only for one command.
To commit as an other user without having to change your settings in .gitconfig :
git -c user.email = mail@example commit -m "some message"
Note: for that example you don't need to precise both
user.email, git will complete the missing information from the previous commits.
# Setup a proxy
If you are behind a proxy, you have to tell git about it:
git config --global http.proxy http://my.proxy.com:portnumber
If you are no more behind a proxy:
git config --global --unset http.proxy
| ||Edits the system-wide configuration file, which is used for every user (on Linux, this file is located at |
| ||Edits the global configuration file, which is used for every repository you work on (on Linux, this file is located at |
| ||Edits the respository-specific configuration file, which is located at |