Intro
“A rolling stone gathers momentum.” – anonymous fortune
Git is one of those tools that grows with you. At first, you’re just trying to commit
without breaking things, then one day you realize Git has a whole personality you can tweak—aliases, safer defaults, and even custom color schemes.
This guide is the companion piece to my earlier post Git-Fu. That one focused on daily commands and workflows. This one goes under the hood: git config
, what lives in the config files, and how you can bend Git to your will.
How git config
Works
Git’s configuration is layered into three scopes:
- System: applies to all users
- Linux/Mac:
/etc/gitconfig
- Windows:
C:\Program Files\Git\etc\gitconfig
- Linux/Mac:
- Global: applies to you
- Primary:
~/.gitconfig
- Alternative:
~/.config/git/config
(XDG standard)
- Primary:
- Local: applies to a single repo (
.git/config
)
Git reads these in order, with more specific scopes overriding broader ones. So a local setting beats a global one, which beats a system one.
The safe way to set values is with the git config
command, which writes to the correct file for you. For example:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Use --system
, --global
, or --local
to control the scope. Handy flags include --get
, --unset
, and --list
.
See everything Git knows about you right now with:
git config --list --show-origin
Where git config
Lives (Persistence, Saving & Resetting)
When you run git config
, you’re not changing runtime state — you’re editing a config file. That’s why these tweaks persist across reboots and repos.
Saving Your Config
Back up everything:
git config --global --list > my-gitconfig.txt
Or just a subset:
git config --global --get-regexp '^alias\.' > my-aliases.txt
Restoring a Config
Reapply from a dump:
while read key value; do
git config --global "$key" "$value"
done < my-gitconfig.txt
Or just copy ~/.gitconfig
between machines.
Resetting to Defaults
Remove a section:
git config --global --remove-section alias
Unset a single key:
git config --global --unset core.editor
Full reset:
mv ~/.gitconfig{,.bak} # quick backup
# or, if you’re feeling reckless
rm ~/.gitconfig
⚠️ Nukes everything—identity, aliases, colors, etc.
Use the mv
method unless you’re 100% sure. Back up first!
Takeaways
git config
is persistent because it writes to config files.- You can save and restore with simple dump/reapply steps.
- Resetting can be surgical (
--unset
) or nuclear (rm ~/.gitconfig
).
Knowing this up front makes the cheatsheet more useful, because you’ll understand where the settings live and how to move them around.

Cheatsheet: Useful Git Config Commands
The examples below use git config
commands, but you can also open your config file directly with:
git config --edit
Quick Start: 5 Safe Defaults
If you only set a handful of Git configs, make it these. They improve safety, keep repos tidy, and save you headaches later:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main # new repos start on 'main'
git config --global push.default simple # safer pushes
git config --global fetch.prune true # auto-clean dead branches
That’s it—your identity + three defaults. You can stop here and still have a nicer Git.
When you’re ready, scroll down for more customization (aliases, pretty logs, colors, etc.).
Identity
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Usability Defaults
git config --global init.defaultBranch main # new repos start with 'main'
git config --global push.default simple # safer pushes
git config --global fetch.prune true # auto-clean old branches
git config --global pull.rebase false # or true if you’re a rebasing fan
Editor
git config --global core.editor "nano" # or vim, code --wait, etc.
git config --global diff.tool vimdiff # or your preferred diff tool
git config --global merge.tool vimdiff # or your preferred merge tool
Pretty Logs
git config --global format.pretty oneline
git config --global log.abbrevCommit true
git config --global log.date relative
Safer Merges
git config --global merge.ff only
git config --global diff.mnemonicprefix true
git config --global rerere.enabled true # reuse recorded resolutions
Aliases (muscle memory FTW)
Aliases let you shorten Git commands into quick shorthands. For example:
git config --global alias.st status
Now instead of typing git status
, you can just type:
git st
That’s all aliases do—they don’t add new features, but they save keystrokes and speed up common commands. Aliases can point to any Git verb, including ones with arguments. For example:
git config --global alias.lg "log --oneline --decorate --graph --all"
git lg # expands to 'git log --oneline --decorate --graph --all'
And here’s the cool part: if your alias starts with !
, Git treats it as a raw shell command instead of a Git subcommand. That means you can make Git run non-Git commands—or Git commands wrapped in shell logic:
git config --global alias.today '!date'
git today # runs your system 'date' command
git config --global alias.root '!git rev-parse --show-toplevel'
git root # prints the repo’s root directory
Note:
Aliases that start with !
run exactly as written in your shell. They don’t take extra arguments the way normal Git commands do—git root sub/dir
won’t work. For more flexibility, write a shell script and call it from your alias.
Here are some popular everyday aliases you can copy straight in:
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm 'commit -m'
git config --global alias.lg "log --oneline --decorate --graph --all"
🎨 How Git Colors Work
Git doesn’t store colors itself—it just spits out ANSI escape codes. Your terminal decides what “yellow” or “cyan” actually looks like. That’s why the default yellow sometimes looks like Dijon mustard depending on your theme.
Git supports three kinds of values:
- Named ANSI colors:
red
,green
,blue
,cyan
,yellow
,magenta
,white
,black
- Attributes:
bold
,ul
(underline),reverse
,blink
- Hex RGB (
#rrggbb
) since Git 2.16 — the most reliable way to get exact shades across terminals
Quick Test
If you just want to see Git output in color, enable it globally:
git config --global color.ui always
Now run git status
or git diff
— you’ll get Git’s built-in red/green/yellow scheme.
# Test your new colors
git status
git log --oneline --decorate -10
git diff HEAD~1 HEAD
git branch -a
git grep "function" # (if you have any code files)

Sample Theme: “Cool Dark”
Here’s a complete theme you can paste in to try out. It uses golden yellow, light cyan/blue, mint green, and bright grey accents chosen for a black terminal background.
Paste the whole block into your terminal (or save as a script). VS Code’s inline color picker (which appears when you hover over hex colors like #ffd75f
) makes customizing these colors especially easy.
git config --global color.ui always
# ── Branches ──
# Affects 'git branch' output and branch decorations in 'git log'
git config --global color.branch.current "#ffd75f" # golden yellow (current branch)
git config --global color.branch.local "#5fd7ff" # light cyan (local branches)
git config --global color.branch.remote "#87afff" # soft sky blue (remotes)
# ── Diffs ──
# Affects 'git diff' output
git config --global color.diff.meta "#ffd75f" # metadata (index info, etc.)
git config --global color.diff.frag "#5fd7ff" # hunk headers
git config --global color.diff.old "#ff5f5f" # red for removed lines
git config --global color.diff.new "#87ffaf" # mint green for added lines
git config --global color.diff.whitespace "#ff5f87" # pink highlight for whitespace errors
git config --global color.diff.commit "#5fd7ff" # commit hashes in 'git log --oneline' (older Git)
# ── Status ──
# Affects 'git status' output
git config --global color.status.added "#87ffaf" # mint green (staged new files)
git config --global color.status.changed "#ffd75f" # yellow (modified files)
git config --global color.status.untracked "#5fd7ff" # cyan (new untracked files)
git config --global color.status.branch "#bcbcbc" # grey (branch info line)
# ── Grep ──
# Affects 'git grep' output
git config --global color.grep.match "#ffd75f" # yellow (matches)
git config --global color.grep.filename "#5fd7ff" # cyan (filenames)
git config --global color.grep.linenumber "#bcbcbc" # grey (line numbers)
# ── Log / Decorations ──
# Affects 'git log --decorate' output
git config --global color.decorate.head "#87ffaf" # mint green (HEAD)
git config --global color.decorate.branch "#5fd7ff" # cyan (local branches)
git config --global color.decorate.remoteBranch "#ffd75f" # yellow (remote branches)
git config --global color.decorate.tag "#ff5f87" # pink (tags)
# ── Interactive ──
# Affects interactive commands (git rebase -i, git add -p)
git config --global color.interactive.prompt "#ffd75f" # yellow (prompts)
git config --global color.interactive.header "#87afff" # blue (section headers)
git config --global color.interactive.help "#bcbcbc" # grey (help text)
git config --global color.interactive.error "#ff5f5f" # red (errors)
# ── Pager highlight ──
# Affects search matches inside 'less'
git config --global color.pager.highlight "#87afff" # soft blue
This is what the exact same theme looks like if you edit your 👀 View the same theme in INI format
~/.gitconfig
directly instead of running commands:[color]
ui = always
[color "branch"]
current = #ffd75f
local = #5fd7ff
remote = #87afff
[color "diff"]
meta = #ffd75f
frag = #5fd7ff
old = #ff5f5f
new = #87ffaf
whitespace = #ff5f87
commit = #5fd7ff # commit hashes (older Git)
[color "status"]
added = #87ffaf
changed = #ffd75f
untracked = #5fd7ff
branch = #bcbcbc
[color "grep"]
match = #ffd75f
filename = #5fd7ff
linenumber = #bcbcbc
[color "decorate"]
head = #87ffaf
branch = #5fd7ff
remoteBranch = #ffd75f
tag = #ff5f87
[color "interactive"]
prompt = #ffd75f
header = #87afff
help = #bcbcbc
error = #ff5f5f
[color "pager"]
highlight = #87afff

Resetting to Defaults
If you want Git’s classic red/green/yellow back, just clear your overrides:
git config --global --remove-section color.branch 2>/dev/null
git config --global --remove-section color.diff 2>/dev/null
git config --global --remove-section color.status 2>/dev/null
git config --global --remove-section color.interactive 2>/dev/null
git config --global --remove-section color.grep 2>/dev/null
git config --global --remove-section color.pager 2>/dev/null
git config --global --unset color.ui 2>/dev/null
📚 Further Reading
Conclusion

Git config is where you make Git yours. Start with the essentials—your name, safe defaults, a couple of aliases—and once you’re comfortable, branch into aesthetics. A splash of cyan and a better yellow can turn Git from hostile text walls into something scannable at a glance.
This article is a companion to Git-Fu.
If you’ve got tips, tricks, or a cool theme of your own, I’d love to hear about it: feedback@adminjitsu.com
Happy committing ✨