Git Config Essentials
Set identity, defaults, and aliases for Git on a new machine.
- git config
- git identity
- git alias
- git default branch
- git setup
Git Config Essentials
Set identity, defaults, and aliases for Git on a new machine.
Commands
| Command | What it does |
|---|---|
git config --global user.name "Your Name" | Set commit author name |
git config --global user.email "you@example.com" | Set commit author email |
git config --global init.defaultBranch main | New repos default to main |
git config --list --show-origin | Show all settings and where they come from |
git config --global alias.st status | Shortcut: git st for status |
git config --global core.editor "code --wait" | Use VS Code as commit editor |
Example
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
git config --list | grep user
FAQ
Where is global config stored?
In ~/.gitconfig (or ~/.config/git/config); repo-local overrides live in .git/config.
How do I use a different identity for one repo?
Run git config user.email without --global inside that repo; it overrides the global value.
常见问题
Where is global config stored?
In ~/.gitconfig (or ~/.config/git/config); repo-local overrides live in .git/config.
How do I use a different identity for one repo?
Run git config user.email without --global inside that repo; it overrides the global value.
Git
Git Clone and Init
Start a repo from scratch or copy a remote repository locally.
Git Add and Commit
Stage changes and record them as commits with clear messages.
Git Branch Basics
Create, list, rename, and delete branches for parallel work.
Git Switch and Checkout
Move between branches and restore files without losing work.