Git Configuration & Aliases
Five minutes of setup makes Git faster and friendlier forever. By the end of this lesson you'll have configured your identity, picked your editor, and built a set of short aliases that turn long commands into two-letter shortcuts.
Learn Git Configuration & Aliases in our free Git course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…
Part of the free Git course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
What You'll Learn
1️⃣ Set Your Identity
Git stamps every commit with a name and email. Set them once with --global so they apply to all your repos. Use the same email as your GitHub account so your commits link back to your profile.
2️⃣ The Three Scopes
Config exists at three levels: --system (all users), --global (all your repos), and --local (just this repo, the default). Git reads them in that order, so the most specific value wins — handy for using a work email in one repo while keeping your usual one everywhere else.
3️⃣ Aliases — Your Own Shortcuts
Aliases live under the [alias] section and turn long commands into short ones. Define st , co , lg and use them like real subcommands. Start an alias value with ! to run a full shell command.
Your turn. Set your name globally and add a one-letter status alias. Fill in the two blanks.
4️⃣ Editor & Other Handy Settings
A few one-time settings smooth everything out: core.editor picks the editor Git opens, init.defaultBranch names the starting branch for new repos, and color.ui turns on colour. Remove any setting with --unset .
Common Errors (and the fix)
- Commits show the wrong author: a local override is in play, or identity was unset. Run git config --list --show-origin and fix or --unset the offending value.
- Editor never opens / hangs: a GUI editor without --wait returns immediately, so Git thinks you wrote nothing. Use core.editor "code --wait" .
- Alias does nothing or errors: you may have set it locally in a different repo, or the value needs quotes. Multi-word values must be quoted: alias.lg "log --oneline" .
- "command not found" from a ! alias: shell aliases run from the repo root and need the tools on your PATH — test the raw command first.
- Forgetting --global: without it, git config writes to the current repo only, so the setting "disappears" in other repos.
Pro Tips
- 💡 Edit the file directly: git config --global --edit opens ~/.gitconfig for bulk changes.
- 💡 Great starter aliases: st=status , co=checkout , lg=log --oneline --graph --all , last=log -1 HEAD .
- 💡 Per-directory identity: use a conditional include ( includeIf "gitdir:~/work/" ) to auto-switch your work email.
- 💡 Sync across machines: keep your ~/.gitconfig in a dotfiles repo.
📋 Quick Reference
Command
Purpose
git config --global user.name "X"
Set your commit name everywhere
git config --global alias.st status
Create the alias git st
git config --list --show-origin
List all values and their files
git config --global core.editor "..."
Choose your editor
git config --global init.defaultBranch main
Name the starting branch
git config --unset key
Remove a setting
Frequently Asked Questions
Mini-Challenge: Build Your Starter Config
No commands given this time — just the plan. Configure a fresh machine the way a pro would, all in your global config.
🎉 Lesson Complete!
- ✅ --global sets your identity and prefs for every repo
- ✅ Three scopes — system, global, local — with the most specific winning
- ✅ Aliases turn long commands into short ones; ! runs a shell command
- ✅ core.editor and init.defaultBranch are worth setting once
- ✅ --list --show-origin debugs surprising values
- ✅ Next lesson: push a branch and open your first GitHub pull request
Practice quiz
Which command sets your name for ALL repos on your machine?
- git config user.name "You"
- git config --system user.name "You"
- git config --global user.name "You"
- git name "You"
Answer: git config --global user.name "You". --global writes to ~/.gitconfig, applying to every repo for your user.
Where does --global config live?
- In ~/.gitconfig (your home directory)
- In each repo's .git/config
- In /etc/gitconfig
- In the cloud
Answer: In ~/.gitconfig (your home directory). Global config is stored in ~/.gitconfig and applies to all of your repositories.
Which scope wins when the same key is set globally and locally?
- Global always wins
- Whichever was set first
- They are merged
- The local (repo) value overrides the global one
Answer: The local (repo) value overrides the global one. Git applies system, then global, then local — the most specific (local) value wins.
How do you create an alias 'st' for 'status'?
- git alias st status
- git config --global alias.st status
- git config st=status
- git st = status
Answer: git config --global alias.st status. git config --global alias.st status defines the alias under the [alias] section.
After 'git config --global alias.co checkout', what does 'git co main' do?
- Runs git checkout main
- Nothing
- Creates a branch
- Errors
Answer: Runs git checkout main. The alias expands 'co' to 'checkout', so git co main runs git checkout main.
How do you make an alias that runs a non-git shell command?
- Prefix with #
An alias value starting with ! runs as a shell command, e.g. alias.cleanup = !git ...
Which setting controls the editor Git opens for commit messages?
- core.pager
- core.editor
- commit.editor
- user.editor
Answer: core.editor. core.editor sets the editor, e.g. git config --global core.editor "code --wait".
How do you list every config value and where it came from?
- git config --all
- git show config
- git config --dump
- git config --list --show-origin
Answer: git config --list --show-origin. --list --show-origin prints each value with the file it was read from.
What's a safe value for the default branch name of new repos?
- core.branch main
- init.defaultBranch main
- branch.default main
- git default main
Answer: init.defaultBranch main. git config --global init.defaultBranch main sets the initial branch name for git init.
How do you remove a config entry?
- git config --delete key
- git config --remove key
- git config --unset key
- git unset key
Answer: git config --unset key. git config --unset <key> removes a single value (use --unset-all for multiples).
Continue this course
- Previous: Hunting Bugs with git bisect
- Next: GitHub Pull Requests & Code Review