The problem: final_v2_REAL.docx
You have probably seen a folder like this, or made one:
report.docx
report_final.docx
report_final_v2.docx
report_final_v2_REAL.docx
report_final_v2_REAL_davids_edits.docx
This is version control done by hand, and it breaks in the same ways every time. Nobody remembers what changed between v2 and v2_REAL. You can't tell which copy is the latest. If two people edit copies at the same time, someone has to merge them by eye. And the copies pile up until the folder is mostly noise.
Git solves the same problem properly. It keeps one working folder for your project and stores every saved version in a hidden database inside that folder. Each saved version is a snapshot of the whole project at that moment. Git calls it a commit. Each commit records:
- what the files looked like
- who made it (your name and email)
- when it was made
- why, in a short message you write
Think of a game's save points rather than a pile of photocopies. You keep playing in one world, and you can go back to any earlier save point whenever you want.
| Copying folders | Git |
|---|---|
| Many copies of the same files | One working folder, history stored once |
Version names you make up (v2_REAL) |
Every snapshot has an ID, an author, a date and a message |
| "What changed?" means comparing files by eye | Git shows you the exact lines that changed |
| Merging two people's copies by hand | Git merges changes and flags the lines that clash |
In this level you install Git, tell it who you are, and create your first repository. You'll make your first commit in the next level.
Step 1: Install Git
Git is a free command-line program. Install it from the official site, git-scm.com:
# Windows: download "Git for Windows" from https://git-scm.com/install/windows
# or install it from a terminal with winget:
winget install --id Git.Git -e --source winget
# macOS: Apple's Command Line Tools include Git...
xcode-select --install
# ...or, if you use Homebrew:
brew install git
# Debian / Ubuntu Linux:
sudo apt-get install git
On Windows, the installer also gives you Git Bash, a terminal where the commands in this course work exactly as written. The installer's default options are fine for now.
Next, open a new terminal window and check that Git is installed:
git --version
# git version 2.56.0 <- your number may differ; any recent 2.x is fine
Gotcha: if you see
git: command not foundor'git' is not recognized, the terminal you're using was opened before the install finished. Close it, open a new one and try again.
Step 2: Tell Git who you are
Every commit is stamped with a name and an email. Set them once, for every repository on your machine:
# --global means "for my user account, in every repository"
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
# Optional but recommended: name the first branch of new repos "main"
# (works in Git 2.28 and later)
git config --global init.defaultBranch main
Why the last line? Out of the box, current Git still names the first branch master and prints a hint about it. GitHub and the other big hosts use main, and the Git project plans to switch its default to main in Git 3.0. Setting it now keeps you consistent with the rest of this course.
Now check what Git has stored:
git config --list
# user.name=Ada Lovelace
# user.email=ada@example.com
# init.defaultbranch=main
# ...plus other lines your installer set
# Ask for a single value:
git config user.name
# Ada Lovelace
# See which file each setting comes from:
git config --list --show-origin
# file:C:/Users/Ada/.gitconfig user.name=Ada Lovelace
--global settings live in a file called .gitconfig in your home folder (~/.gitconfig, or C:\Users\<you>\.gitconfig on Windows). If you run git config user.email ... without --global inside a repository, the setting applies to that repository only and overrides the global one. That's useful when one repository should use your work email.
Best practice: use the email you'll use on GitHub later. Commits are linked to accounts by email address, so a typo here means your work won't show up as yours.
Gotcha: if
git config --listshowsuser.nametwice, the last value listed wins.--show-origintells you which file to fix.
Step 3: Create your first repository
A repository (repo) is a folder that Git is tracking. git init turns an ordinary folder into one:
# Make a practice folder and go into it
mkdir git-practice
cd git-practice
# Turn it into a Git repository
git init
# Initialized empty Git repository in /home/ada/git-practice/.git/
That message points to the key detail: Git created a hidden folder called .git. That's the database where all your snapshots will go. Your own files stay right where they are, and Git keeps its bookkeeping in .git.
Never edit or delete
.gitby hand. Deleting it deletes all of your history. The folder becomes ordinary files again.
Now ask Git what it sees:
git status
# On branch main
#
# No commits yet
#
# nothing to commit (create/copy files and use "git add" to track)
Each line tells you something:
- On branch main: you're on the default line of work (branches come in level 4).
- No commits yet: the repository exists but has no snapshots so far.
- nothing to commit: the folder is empty, so there's nothing to save.
If you run git status in a folder that is not a repository, you get this instead:
fatal: not a git repository (or any of the parent directories): .git
git status is the command you'll run most often. Whenever you're unsure what's going on, run it.
Gotcha: don't run
git initin your home folder or on your Desktop. Git would then track everything under it. Always make a dedicated project folder first.
Check your result
Run these in git-practice:
git --version # prints a version number
git config user.name # prints your name
git config user.email # prints your email
git status # "No commits yet"
ls -a # the list includes .git
If all five work, you're ready for level 2, where you'll make your first real commit.
Key takeaways
- Version control replaces piles of copies with one folder plus a history of snapshots (commits). Each commit records what changed, who made it, when, and why.
- Install Git from git-scm.com and confirm it with
git --version. - Set your identity once with
git config --global user.nameanduser.email. Check it withgit config --list(add--show-originto see which file each setting comes from). git initcreates a repository by adding a hidden.gitfolder. Never delete that folder unless you mean to delete the history.git statustells you where you stand. In a new repo it says No commits yet.