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.
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 .
📋 Quick Reference
No commands given this time — just the plan. Configure a fresh machine the way a pro would, all in your global config.
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).