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.
🎯 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
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
| Git | GitHub | |
|---|---|---|
| What it is | A program on your computer | A website that hosts Git projects online |
| Works offline? | Yes, completely | No |
| Made by | Linus Torvalds, in 2005; free and open source | GitHub (owned by Microsoft); free plans available |
| You use it to | Record versions of your project | Back 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 computer | How to install |
|---|---|
| Windows | Download 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. |
| macOS | Open 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:
git --versionOutput
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:
| Command | Meaning | Example |
|---|---|---|
pwd | Print working directory: which folder am I in? | pwd |
ls | List the files in this folder | ls |
cd | Change directory: go into a folder (cd .. goes up one) | cd Documents |
mkdir | Make a new folder | mkdir notes |
cat | Show what is inside a file | cat index.html |
mkdir notes
cd notes
pwd
cd ..
lsOutput
/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).
git config --global user.name "Asha Kumar"
git config --global user.email "asha@example.com"
git config --global init.defaultBranch mainCommands that succeed often print nothing at all. To check the settings, ask Git for them:
git config user.name
git config user.email
git config init.defaultBranchOutput
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:
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.
- Install Git for your computer using the table above, then open a terminal.
- Run the three
git config --globalcommands with your own name and email. - Run
git config user.name,git config user.emailandgit config init.defaultBranch.
Show the solution
git config user.name
git config user.email
git config init.defaultBranchOutput
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
mkdir drafts
cd drafts
pwd
cd ..
lsOutput
/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. Which statement is true?
2. Which command shows the folder you are currently in?
3. Why set user.name and user.email?
4. On Windows, which terminal does this course use?
Mark this lesson complete
Finished this lesson?
When you have worked through the examples and exercises, mark it complete to save your progress.