Git and GitHub course menu
How to Install Git and Set Up Your Name and Email
Install Git on Windows, macOS and Linux, check the version, set your name and email with git config, choose the default branch name and editor, and open a terminal.
On this page
Install Git#
Windows: download the installer from git-scm.com and accept the defaults. It includes Git Bash, a terminal that understands the commands used in this course. Use Git Bash for all the lessons.
macOS: run git --version in Terminal. If Git is missing, macOS offers to install the Command Line Tools. You can also use Homebrew:
brew install gitLinux (Ubuntu or Debian):
sudo apt update
sudo apt install gitCheck that it works:
git --versiongit version 2.54.0.windows.1Your version number may differ. Any recent version works with this course, though git switch and git restore need Git 2.23 or later.
Tell Git who you are#
Every commit records an author. Set your name and email once per computer. --global means "for all my repositories":
git config --global user.name "Asha Rao"
git config --global user.email "[email protected]"Use your own name and the email you will use on GitHub. Check what is stored:
git config user.name
git config user.emailAsha Rao
[email protected]Name the default branch main#
Newer projects call their first branch main. Make that your default:
git config --global init.defaultBranch mainChoose an editor#
Git opens a text editor for longer commit messages and some other commands. If you use VS Code:
git config --global core.editor "code --wait"--wait makes Git wait until you close the file. The default on many systems is Vim. If you end up in Vim by accident, press Esc, type :q! and press Enter to leave.
Line endings on Windows#
Windows ends text lines differently from macOS and Linux. The Git for Windows installer sets core.autocrlf to true, which stores files with Linux-style endings and gives you Windows-style endings when you check them out, so teams on different systems do not see every line as changed. Leave it as it is. On macOS and Linux no change is needed.
Terminal basics#
These are the only terminal commands you need for this course:
Getting help#
git help commit # full manual page
git commit -h # short summary of the optionsCommon mistakes#
Practice#
Practice exercise
Print the value of user.name, and then print the default branch setting.
Show solution
git config user.name
git config init.defaultBranchAsha Rao
mainKey takeaway#
Finished this lesson?