Key idea
Git needs three things before your first commit: to be installed, to know your name and email (it writes them into every commit), and an editor you know how to close. Set them once and every repository on your machine uses them.
Install it
Run git --version. If it prints a version, skip ahead. If not, get Git from git-scm.com:
- macOS: running
git --versionoffers to install Apple's command line tools, which include Git. Say yes. - Windows: install Git for Windows. It includes Git Bash, a terminal where every command in this module works as written.
- Linux: use your package manager, for example
sudo apt install git.
Tell Git who you are
git config --global user.name "Ada Lovelace"
git config --global user.email "[email protected]"
Every commit records this name and email, and anyone who can read the repository can see them. If you'd rather not publish your email, GitHub gives you a private noreply address under Settings, then Emails. It looks like [email protected], and commits made with it still count as yours. See Setting your commit email address on docs.github.com.
Check both with git config --global --list.
Pick an editor, or skip it
Some commands, such as a merge, open an editor for a message. The default is often Vim, which confuses everyone the first time. Choose one you know:
git config --global core.editor "nano" # a simple terminal editor
git config --global core.editor "code --wait" # VS Code, if you use it
Or avoid the editor: git commit -m "message" and git merge --no-edit never open one. Stuck in Vim anyway? Press Esc, type :wq and press Enter to save and quit.
Leave the pager
git log and git diff show long output a page at a time. Press Space for the next page and q to get your prompt back.
Check yourself