Installing and setting up
Last updated
Before Git can save anything, it needs to know who you are. In this lesson you'll install Git, tell it your name and email, choose the name of the first branch, and see where those settings are kept.
By the end of this lesson you can
- Install Git and check its version
- Set your name and email, and choose an email you're happy to make public
- Set the first branch's name to main
- Say where Git keeps settings for the system, for you, and for one repository
Installing Git
Git is free. Download it from git-scm.com, the Git project's own site, and check that it worked by asking for its version:
git --version git version 2.55.0
Any recent version works for this course. Every lesson was checked with Git 2.55.
Telling Git who you are
Every commit records who made it: a name and an email. Git won't make a commit until it knows them, so you set them once, for all your repositories, with --global:
git config --global user.name "Ana Reyes" git config --global user.email "[email protected]"
Quotes keep a name with a space in it together. The name can be anything you want others to see.
One more setting. The first line of work in a new repository is called a branch (Stage 3 explains branches). For years Git named it master. Many projects and hosting sites now use main, and Git's own plan for version 3.0 makes main the default. Setting it yourself means your repositories look the same whatever version you have:
git config --global init.defaultBranch main
Try it. This sandbox has a fresh Git with no settings. git config --global --list shows what you've set.
- Check Git is installed with
git --version - Set your name (any name you like)
- Set your email (use
[email protected]here) - Make
mainthe first branch’s name - List your settings to check them
You are in your home folder, /home/ana. Type help to see what this terminal knows.
Where settings live
Git keeps settings at three levels. Each level overrides the one above it:
| Level | Option | Applies to | Kept in |
|---|---|---|---|
| System | --system | every user on the computer | a file in Git's install folder |
| Global | --global | every repository of yours | .gitconfig in your home folder |
| Local | (none) | one repository | .git/config inside it |
So you can use one email for everything, and a different one in one repository: run git config user.email "..." inside that repository, without --global. The capstone uses this to play two people on one computer.
git config --list --show-origin on your own computer shows every setting and the file it came from.
An editor for Git to open
Some Git commands open a text editor for you to write in, such as a commit message when you don't give one on the command line. If you never set one, Git usually opens Vim, which is hard to leave if you've never used it. (Press Esc, type :q! and press Enter.)
Choose an editor you know. For Visual Studio Code:
git config --global core.editor "code --wait"
--wait makes Git wait until you close the file. Pro Git's setup chapter lists the line for other editors, and the Git for Windows installer asks you to choose one.
The sandbox in this course has no editor window for Git to open, so it always asks you to give the message with -m, as you'll see in the next lesson.
Spot the trap: an email you don't want public
Ana sets user.email to her personal email. Months later she puts Kusina on a hosting site so Carla can join, and makes it public so the whole family can read the recipes.
What happens if…
Choose your commit email before you make commits you'll share. If you're under 18, or just private, use the hosting site's noreply address from the start.
Check what you learned
Sources
Every command on this page behaves as these pages describe, and the sandbox prints what Git 2.55 prints. Hosting features (pull requests, protected branches) come from the host’s own documentation.
- Git downloads: installers for Windows, macOS and Linux
- Pro Git: First-Time Git Setup: name, email, editor and the three levels of settings
- Git documentation: git-config: --global, --list and where each file is
- Git documentation: git-init, --initial-branch: init.defaultBranch, and the change to main planned for Git 3.0
- GitHub Docs: Setting your commit email address: commit emails are public, and GitHub's private noreply address