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

SectionTimeRequired?
How Git Works5 min⚑ Required
Git Terminology5 min⚑ Required
Git Commands Reference5 min⚑ Required
Try It Out60 min⚑ Required
Reflect15 min⚑ Required
Extra ResourcesOpen◎ 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.

CommandWhat it does
git initTurns the current folder into a Git repository
git statusShows what has changed and what is ready to commit
git add -AStages all changed files, ready to be committed
git commit -m "message"Saves a snapshot with a description of what changed
git pushSends your commits up to GitHub
git pullDownloads 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 configSets up Git options (name, email, defaults)
git helpLists 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:

  1. Run pwd to confirm you are in the right folder
  2. Make sure you have no work you want to keep
  3. Run rm -rf .git

Git workflow flowchart

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-test
cd git-test
git 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 main
git 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

  1. Go to github.com
  2. Click Create New... > New Repository
  3. Set yourself as the owner
  4. Name it git-test
  5. Leave all other settings as default
  6. 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

  1. Go to github.com
  2. Click Create New... > New Repository
  3. Name it git-test-2
  4. Leave everything else as default
  5. 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.git
cd 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.md
code .

Write something in the file. Save it. Then:

git add -A
git 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 notes
touch 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

LevelYou can...
🪨Intro ClimbCreate both repos and push at least one file to each⚑ Required
🧗Core AscentMake multiple commits with meaningful messages and push them to GitHub⚑ Required
🏔️SummitExplain the difference between a local and remote repo without notes◎ Optional

Reflect

Add your answers to the same document as your previous reflections.

Questions:

  1. What are the two different ways of creating a new Git repository?
  2. What is the difference between a local and a remote repository?
  3. How confident do you feel with the add–commit–push workflow right now, on a scale of 1–10?
  4. 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.