BeginnerLesson 2 of 306 min read

Installing Git, the Command Line and Your First Setup

Open a terminal, learn the five commands that get you around, install Git and tell it who you are before your first commit.

In this lesson you will

  • Open a terminal and move around folders
  • Check that Git is installed
  • Set your name, email and default branch
  • Read an error message calmly

About 24 minutes

“Just run git status”

Dev has set up a project for the garden club and sends Nia a message: “Pull it down and run git status.” Nia stares at the message. Run it where? Typed into what? This lesson answers those questions. You will install Git, open a terminal, learn the five commands that get you around, and tell Git who you are. After today, a message like Dev’s will make sense.

The command line is a conversation

A terminal is a window where you type instructions and the computer types back. It looks old fashioned, but it is simply a precise way to ask for things, and Git was designed around it. Every example in this course shows the text you type after a $ sign, followed by what the computer prints back. You type everything after the dollar sign, and you do not type the dollar sign itself.

How you open a terminal depends on your system. On Windows, the Git installer includes a program called Git Bash, and Windows also has PowerShell and Command Prompt. On a Mac you open the Terminal app. On Linux you open your distribution’s terminal. Git commands are the same everywhere. A few of the small helper commands below differ slightly on Windows PowerShell, so if you are unsure, Git Bash gives you the same experience as the examples here.

Getting Git

Git is free. You can download the installer from the official Git website, or use a package manager if your system has one. Most installers ask several questions. The default answers are safe for a beginner, so you can click through them. The options and their wording change between versions, so check the page you download from for current steps. When it finishes, close any terminal that was open and open a new one, so the computer notices the new program.

To check that it worked, ask Git for its version with git --version. The session further down shows the answer from the computer that built this lesson. Yours will show your own version number, and any recent one is fine for this course.

Five commands for getting around

Command What it does
pwd Shows where you are now
ls -a Lists files, including hidden ones
cd folder Moves into a folder
mkdir name Makes a new folder
cat file Prints a file on screen

Here they are in a real session. Read it from top to bottom. It also includes two things you have not met yet: a deliberate mistake, and the setup commands that come next.

$ pwd
/home/nia
$ ls -a
.
..
$ mkdir garden
$ cd garden
$ pwd
/home/nia/garden
$ git --version
git version 2.43.0
$ git status
fatal: not a git repository (or any of the parent directories): .git
$ git config --global user.name "Nia Okafor"
$ git config --global user.email "nia@example.com"
$ git config --global init.defaultBranch main
$ git config --global --list
user.name=Nia Okafor
user.email=nia@example.com
init.defaultbranch=main
$ cat ~/.gitconfig
[user]
	name = Nia Okafor
	email = nia@example.com
[init]
	defaultBranch = main
$ ls -a ~
.
..
.gitconfig
garden

Reading the mistake

The line git status failed, and that is useful. Git said it is not a git repository. The folder garden exists, but nobody has told Git to watch it, so there is no history to report. Next lesson you will fix that. For now, notice the habit of reading what the computer says. Error messages in Git are written in plain language, and the answer is usually in the first line.

Telling Git who you are

Every commit records who made it. So before your first commit, you set a name and an email address once, using git config --global. The word global means “for every project on this computer”. Git stores these settings in a small text file called .gitconfig in your home folder, which the session above printed with cat. The same session also set init.defaultBranch to main, which is the name Git gives the first branch of each new project. Older guides show the name master. Git has allowed this setting since version 2.28, and many tools now use main. Either name works.

Be careful with the email. It is stored in every commit, and if you share a project online, other people can see it. Use an address you are happy to make public. GitHub also offers a private “no-reply” address you can use instead, in its account settings, so look there when you create your account.

Common mistake: committing before configuring

Skipping the name and email setup. Without it, Git either refuses to commit or guesses a name from your computer, and the wrong name then sits in your history for ever.

Made-up example details

The name and email in this lesson are made up for the example, and the folder is a private test area. Use your own details on your own computer. The installer steps and menu wording differ by system and version, so follow the instructions on the page you download from.

Getting help

Git explains itself. Typing git help commit opens the manual for the commit command, and adding -h after a command, for example git commit -h, prints a short reminder of its options. If a terminal says command not found when you type git, the installation did not finish or the terminal was open before you installed. Close it, open a new one and try again.

Open a terminal, run pwd, make a folder called practice, move into it, and run git --version and your three git config commands. Then run the list command to see the hidden settings file in your home folder.

Practice for this lesson

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

Do you type the dollar sign shown at the start of each example line?

  1. Yes, always
  2. No, it is the prompt; you type only what follows it
  3. Only on a Mac
  4. Only for Git commands

The dollar sign marks the prompt that the terminal prints for you.

Which command shows the folder you are currently in?

  1. mkdir
  2. cat
  3. pwd
  4. git status

pwd printed the path to the home folder in the session.

Why did the first git status fail in the lesson?

  1. The folder was not a Git repository yet
  2. Git was not installed
  3. The folder was empty of text
  4. The terminal was too old

Git said it is not a git repository, because nobody had started one.

What does the word global mean in git config –global?

  1. The setting is sent to GitHub
  2. The setting is secret
  3. The setting applies to every project on this computer
  4. The setting lasts for one day

The settings were saved in the .gitconfig file in the home folder.

Why choose the email address in your Git settings carefully?

  1. It is stored in every commit and may be visible if you share the project
  2. Git sends marketing mail to it
  3. It becomes your password
  4. It must be a work address

Commits carry the author email, so choose an address you are happy to make public.

Summary

  • A terminal is a precise way to ask the computer for things.
  • pwd, ls, cd, mkdir and cat get you around.
  • git config –global sets your name, email and default branch once.
  • Git error messages are written in plain language, so read the first line.

Next lesson

Lesson 3 makes your first repository and your first commit.

Questions

Do I have to use the command line?

Editors and apps can run Git for you, and later lessons mention them. Learning the commands first means you understand what those buttons are really doing.

My version number is different from the lesson. Is that a problem?

No. Any recent version works for this course. The example prints the version of the computer that built the lesson.

Can I change my name or email later?

Yes. Run the same git config command again with the new value. Commits you have already made keep the details they were made with.

Progress is saved in this browser.