Nishaglobal Education logo

What Git and GitHub are, and setting up Git

Understand version control and the difference between Git and GitHub, install Git on Windows, macOS or Linux, learn the five terminal commands you need, and tell Git your name and email.

Lesson 1 of 1135 minQuiz: 4 questions

🎯 By the end of this lesson you will be able to:

  • Explain what version control is and how Git and GitHub differ
  • Install Git and open a terminal in a project folder
  • Configure your name, email and default branch name
Outline
  1. What you'll learn and why it matters
  2. Git and GitHub are different things
  3. Install Git (about 10 minutes)
  4. Five terminal commands you need
  5. Tell Git who you are
  6. Practice
  7. Common mistakes
  8. Recap
  9. Quiz
  10. Mark lesson complete

What you'll learn and why it matters

Have you ever saved files called report-final.docx, report-final-2.docx and report-final-REALLY.docx? Version control solves that properly. It records every change to a project: what changed, when, by whom and why, and lets you go back to any earlier version. Git is the version control tool used by almost every software team in the world, and knowing it is expected in nearly every developer, tester, DevOps and data job.

Git and GitHub are different things

GitGitHub
What it isA program on your computerA website that hosts Git projects online
Works offline?Yes, completelyNo
Made byLinus Torvalds, in 2005; free and open sourceGitHub (owned by Microsoft); free plans available
You use it toRecord versions of your projectBack up, share and collaborate on those projects

Lessons 1 to 7 use only Git, on your own computer, with no account. From lesson 8 you will use a free GitHub account.

Install Git (about 10 minutes)

Your computerHow to install
WindowsDownload the installer from git-scm.com and run it. The default options are fine. It also installs Git Bash, the terminal we use in this course, and Git Credential Manager, which signs you in to GitHub later.
macOSOpen the Terminal app and type git --version. If Git is missing, macOS offers to install the *command line developer tools*; click Install.
Linux (Ubuntu, Debian)In a terminal, run sudo apt install git.

Check that it worked. Open a terminal (on Windows, open Git Bash from the Start menu) and type:

Terminal
git --version

Output

git version 2.53.0

Any version from 2.28 onwards works for this course. Your number may be different. This course was checked with Git 2.53.

Five terminal commands you need

Git is used by typing commands in a terminal: a window where you type a command and press Enter. You only need a handful of everyday commands to move around:

CommandMeaningExample
pwdPrint working directory: which folder am I in?pwd
lsList the files in this folderls
cdChange directory: go into a folder (cd .. goes up one)cd Documents
mkdirMake a new foldermkdir notes
catShow what is inside a filecat index.html
Terminal
mkdir notes
cd notes
pwd
cd ..
ls

Output

/Users/asha/my-website/notes
notes

Tell Git who you are

Every snapshot (called a commit) records who made it. Set your name and email once per computer. Use the email you will use for GitHub. The third line makes new projects use the branch name main, which GitHub uses too (you will learn about branches in lesson 6).

Terminal: run once, with your own name and email
git config --global user.name "Asha Kumar"
git config --global user.email "asha@example.com"
git config --global init.defaultBranch main

Commands that succeed often print nothing at all. To check the settings, ask Git for them:

Terminal
git config user.name
git config user.email
git config init.defaultBranch

Output

Asha Kumar
asha@example.com
main

Finally, choose an editor for the times Git needs you to write a message. If you use VS Code:

Terminal
git config --global core.editor "code --wait"

Without this, Git uses a terminal editor called Vim, which confuses many beginners. (If you ever get stuck in it, type :q! and press Enter to quit without saving.)

Practice

Guided exercise

Set up and check

Install Git, set your name, email and default branch, then print all three settings to check them.

  1. Install Git for your computer using the table above, then open a terminal.
  2. Run the three git config --global commands with your own name and email.
  3. Run git config user.name, git config user.email and git config init.defaultBranch.
Show the solution
Solution
git config user.name
git config user.email
git config init.defaultBranch

Output

Asha Kumar
asha@example.com
main

How to get there: Each command prints one setting. You should see your own name and email, and main. If a line is empty, that setting was not saved: run its git config --global command again, checking the quotes.

Your turn

Move around in the terminal

In your my-website folder, make a folder called drafts, go into it, print where you are, go back up, and list the folder.

Show the solution
Solution
mkdir drafts
cd drafts
pwd
cd ..
ls

Output

/Users/asha/my-website/drafts
drafts

How to get there: mkdir creates the folder, cd drafts goes in, pwd proves where you are, cd .. goes back up, and ls lists the contents of my-website. Your path and other files will be different.

Common mistakes

Typing commands in the Windows Command Prompt or PowerShell

You see: ls, cat or pwd behave differently or are not found

Fix: Use Git Bash on Windows for this course.

Forgetting the quotes around a name with a space

You see: Only your first name is saved, or an error appears

Fix: Write git config --global user.name "Asha Kumar".

Typing Git or GIT

You see: command not found

Fix: Commands are lower case: git.

Getting stuck in the Vim editor

You see: A strange screen with ~ down the side

Fix: Type :q! and press Enter, then set VS Code as your editor.

Recap

  • Version control records every change; Git does it on your computer, GitHub hosts projects online.
  • Install Git (Git Bash on Windows) and check with git --version.
  • pwd, ls, cd, mkdir and cat are enough to move around the terminal.
  • Set user.name, user.email and init.defaultBranch once with git config --global.

Key terms

Version control
A system that records changes to files so you can see history and go back to earlier versions.
Git
A free, open-source version control program that runs on your computer.
GitHub
A website that hosts Git repositories and adds tools for sharing and teamwork.
Terminal
A window where you type commands for the computer to run.

Check your understanding

Answer all 4 questions, then check your answers to see an explanation for each one.

  1. 1. Which statement is true?

  2. 2. Which command shows the folder you are currently in?

  3. 3. Why set user.name and user.email?

  4. 4. On Windows, which terminal does this course use?

Answer all 4 questions to check.

Mark this lesson complete

Finished this lesson?

When you have worked through the examples and exercises, mark it complete to save your progress.