git config
git
Usage
git config [--global] <key> [<value>]Reads and writes git settings; without --global it only touches this repository, which is why a fresh clone forgets the setting.
Common flags
| Flag | Meaning |
|---|---|
| --global | write to ~/.gitconfig for every repository |
| --local | write to .git/config, the default |
| --list --show-origin | print every setting and the file it came from |
| --get <key> | print one value |
| --unset <key> | delete one setting |
| -e | open the config file in your editor |
Examples
git config --global user.email "me@example.com"sets the address every future commit is signed with
git config --global init.defaultBranch mainnew repositories start on main instead of master
git config --list --show-originshows which file each setting comes from
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git config do?
Reads and writes git settings; without --global it only touches this repository, which is why a fresh clone forgets the setting.
Q. How do I type it?
git config [--global] <key> [<value>] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-config