Skip to content

Set up Git

Last updated:

Download Git from git-scm.com/install and run the installer. Git for Windows includes Git Bash: use that terminal for every command here. If your editor has Git built in, it runs the same commands under its interface.

Terminal window
git --version

Git records this identity on every commit you make.

Terminal window
git config --global user.name "Alex Example"
git config --global user.email "alex@example.com"
Terminal window
git config --global init.defaultBranch main

This names the first branch of a new repository main instead of master.

Terminal window
git config --global pull.rebase true

Without this, pulling your own branch after pushing from two machines creates a commit titled something like “Merge branch ‘add-login’ of codebahn.net into add-login”. Rebasing on pull avoids it.

Terminal window
git config --global push.autoSetupRemote true

With this set, git push works on a new branch without typing -u origin <branch> first.

Terminal window
git config --global --list

Git basics is licensed under CC BY 4.0: copy it, adapt it, keep the credit.