First steps · lesson 3 of 8
Commands and ideas in this lesson
Agit --versionis Git installed?
Bgit config --globalsettings for all your repositories
Cuser.name, user.emailwho made each commit
Dinit.defaultBranchthe first branch's name

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:

Terminal
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:

Terminal
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:

Terminal
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.

Terminal
  1. Check Git is installed with git --version
  2. Set your name (any name you like)
  3. Set your email (use [email protected] here)
  4. Make main the first branch’s name
  5. 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:

LevelOptionApplies toKept in
System--systemevery user on the computera file in Git's install folder
Global--globalevery 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:

Terminal
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

Spot the trapAna

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

You run git config --global user.email "[email protected]". Which repositories use that email?
Why set init.defaultBranch to main?
After pushing a public repository, Ana changes user.email. What happens to her old commits?

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.

All sources for Simple Git