Before you can use any command, Git needs to be installed and configured first. This is a one-time setup — you won't need to repeat it for every project.
1. Install Git
macOS
brew install git
(If you don't have Homebrew yet, install it first from brew.sh.)
Linux (Debian/Ubuntu)
sudo apt update && sudo apt install git
Windows
Download the installer from git-scm.com/downloads and follow the setup wizard (the default options are safe for beginners).
2. Verify the installation
git --version
If a version number shows up (e.g. git version 2.43.0), the installation succeeded.
3. Configure your identity
Git attaches your name & email to every commit you make — so this must be set before your first commit.
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
Use the same email as your GitHub account so your commits automatically link to your GitHub profile later.
--global means it applies to every repo on your machine. If you ever need a different identity for one specific project (e.g. a work account vs. a personal one), run the same command without --global inside that project's folder.
4. Set the default branch name
git config --global init.defaultBranch main
This ensures every new repo uses main as the main branch name (the modern standard), instead of master.
5. (Optional) Set a default editor
Git sometimes needs to open a text editor (e.g. to write a longer commit message). The default is often vim, which confuses beginners. Switch to something more familiar:
# VS Code
git config --global core.editor "code --wait"
# nano (simpler than vim)
git config --global core.editor "nano"
6. Check all your settings
git config --list
This shows every setting you've configured so far. If you made a typo, just re-run the git config --global ... command with the correct value — the old value gets overwritten automatically.
Summary
| Command | Purpose |
|---|---|
git --version |
Check Git is installed |
git config --global user.name "..." |
Set the name used in commits |
git config --global user.email "..." |
Set the email used in commits |
git config --global init.defaultBranch main |
Set the default main branch name |
git config --list |
View all active configuration |
Next: create your first repository, either from scratch (git init) or by copying an existing one (git clone).