Git Setup
The Big Idea
Git tracks every change you make to your code — like a save history you can travel back through. In this lesson you will create two Git repositories: one from the command line, one from GitHub. By the end, you will know how to add, commit, and push your work to GitHub.
Your Git workflow — how you commit, push, and structure your work — says a lot about you as a developer. Facilitators will be looking at how you use Git throughout Foundations. More importantly, good Git habits are something every employer expects. The practices you build now will follow you into your career.
Your Roadmap
| Section | Time | Required? |
|---|---|---|
| How Git Works | 5 min | ⚑ Required |
| Git Terminology | 5 min | ⚑ Required |
| Git Commands Reference | 5 min | ⚑ Required |
| Try It Out | 60 min | ⚑ Required |
| Reflect | 15 min | ⚑ Required |
| Extra Resources | Open | ◎ Optional |
How Git Works
Git keeps a full history of your project. Every time you tell Git to save your progress, it takes a snapshot — called a commit. You can look back at any commit, any time.
Think of commits like save points in a video game. Unlike a regular save that overwrites the last one, Git keeps every save point. You can jump back to any point in your history without losing anything.
Git does not save automatically. You have to tell it when you are ready to commit. This is intentional — it means you decide what counts as meaningful progress.
Git Terminology
Show definitions
Command Line — The terminal program you use to type Git commands. On Mac/Linux it is called Terminal. You type text commands instead of clicking with a mouse.
Repository — A folder that Git is tracking. Often called a "repo". It can live on your computer (local) or on GitHub (remote). You can store code, text, and images inside a repo.
Version Control — The reason Git exists. Instead of overwriting your saved file every time, Git keeps snapshots of every version. You can never lose work you have committed.
Commit — A saved snapshot of your repository at a point in time. Each commit has a message describing what changed.
Branch — A separate version of the repository. Branches let multiple people work on the same project without overwriting each other's changes. When the work is done, branches are merged back together.
Git Commands Reference
Show all commands
These are the commands you will use most. They all start with git.
| Command | What it does |
|---|---|
git init | Turns the current folder into a Git repository |
git status | Shows what has changed and what is ready to commit |
git add -A | Stages all changed files, ready to be committed |
git commit -m "message" | Saves a snapshot with a description of what changed |
git push | Sends your commits up to GitHub |
git pull | Downloads the latest commits from GitHub |
git clone [url] | Copies a remote repository to your computer |
git branch [name] | Creates a new branch |
git checkout [name] | Switches to a different branch |
git config | Sets up Git options (name, email, defaults) |
git help | Lists common Git commands |
Note on git init: Only run this inside a folder that is not already a Git repository. If you run git init inside an existing repo, it breaks both. Always check with git status first — if it returns an error saying "not a git repository", you are safe to initialise.
Dangerous command — read before using:
rm -rf .git permanently deletes the Git repository from the current folder. There is no undo. Use this only to fix an accidental git init in the wrong place.
Before running it:
- Run
pwdto confirm you are in the right folder - Make sure you have no work you want to keep
- Run
rm -rf .git
Try It Out
You are going to create two repositories. First from the command line, then from GitHub. Both approaches are useful — you will use both in your career.
Part 1 — Create a Repository from the Command Line
Step 1: Create the folder
In your terminal, navigate to a location that is not already a Git repository. Then run:
mkdir git-testcd git-testgit init
This creates a new folder and turns it into a Git repository.
You may see a message saying the default branch is called master. Run this to change it to main:
git config --global init.defaultBranch maingit branch -m main
Step 2: Create a file
touch readme.md
Open the file in VS Code:
code .
Write something inside readme.md — anything you like. Save the file — Cmd+S on Mac, Ctrl+S on Windows/Linux.
Step 3: Add, commit, and push
You will do these three steps thousands of times. Here they are:
Add — Tell Git which files to include in the next snapshot:
git add -A
The -A means "all" — it stages every changed or new file in the repository. You can also add individual files by name (e.g. git add readme.md), but git add -A is the most common approach and the one you'll use most often.
Run git status to confirm. You should see your file listed under "Changes to be committed".
Commit — Take the snapshot with a message:
git commit -m "add readme"
Run git status again. It should say "nothing to commit, working tree clean".
Do not run git push yet. If you try now, you will get a fatal error — fatal: No configured push destination. That is expected. It just means Git does not know where to send your commits. You need to create a remote repository on GitHub first and link it. That is what the next step does.
Step 4: Create the remote repository on GitHub
- Go to github.com
- Click Create New... > New Repository
- Set yourself as the owner
- Name it
git-test - Leave all other settings as default
- Click Create repository
On the next screen, find the command that starts with git remote add origin. It will look like this (with your username):
git remote add origin git@github.com:YOUR-USERNAME/git-test.git
Run that command in your terminal. This links your local repo to the remote one. You only need to do this once per repo.
Step 5: Push for the first time
Because this is the first push to this branch, run:
git push --set-upstream origin main
After this, you only need git push for future commits.
Head to your repo on GitHub. You should see your readme.md file there.
Part 2 — Clone a Repository from GitHub
This approach starts from GitHub and copies the repo to your computer. It is slightly easier and the one you will use most often.
Step 1: Create the repo on GitHub first
- Go to github.com
- Click Create New... > New Repository
- Name it
git-test-2 - Leave everything else as default
- Click Create repository
On the next screen, make sure the toggle is set to SSH (not HTTPS). Copy the repository URL.
Step 2: Clone it to your computer
In your terminal, navigate to a location that is not already inside a Git repo. Then run:
git clone git@github.com:YOUR-USERNAME/git-test-2.gitcd git-test-2
You may see "warning: You appear to have cloned an empty repository." That is expected.
Step 3: Add some files and push
touch readme.mdcode .
Write something in the file. Save it. Then:
git add -Agit commit -m "add readme"git push
Check GitHub — your file should be live.
Step 4: Experiment
Spend some time adding more files and folders. Try:
mkdir notestouch notes/thoughts.txt
Write something in thoughts.txt. Then add, commit, and push. Do this a few times until the steps feel familiar.
How to know you've nailed it
| Level | You can... | ||
|---|---|---|---|
| 🪨 | Intro Climb | Create both repos and push at least one file to each | ⚑ Required |
| 🧗 | Core Ascent | Make multiple commits with meaningful messages and push them to GitHub | ⚑ Required |
| 🏔️ | Summit | Explain the difference between a local and remote repo without notes | ◎ Optional |
Reflect
Add your answers to the same document as your previous reflections.
Questions:
- What are the two different ways of creating a new Git repository?
- What is the difference between a local and a remote repository?
- How confident do you feel with the add–commit–push workflow right now, on a scale of 1–10?
- What part is still confusing? What would help you understand it better?
The Big Idea (revisited)
git init or git clone to start. git add -A to stage. git commit -m to save a snapshot. git push to send it to GitHub. These four steps are the foundation of everything you will do with Git from here on.
Extra Resources
These are optional. Use them if you want to go deeper.