CSE Roadmap

Common tier · about 5 hours · 11 parts

Part 3 of 11 · 5 min read

Your first repository

Install Git, make a project, save two versions of a file and read the history. Every command is shown with the output Git prints, and what it means.

You will make a tiny project in a few minutes. Follow along on your own computer: the commands are short, and seeing real output is how the ideas stick.

Before you start

  1. Install Git from git-scm.com. On Windows this also installs Git Bash, a terminal that understands the commands below. On macOS and Linux, use the Terminal you already have.
  2. Open a terminal. A terminal is a window where you type commands instead of clicking. Lines starting with $ below are things you type. Do not type the $. Other lines are what Git prints back.
  3. Check it works:
$ git --version
git version 2.43.0

Your version number may differ. Any recent version is fine. If you see "command not found", the installation did not finish or the terminal needs reopening.

Step 1: Tell Git who you are

Every commit records its author, so Git needs your name and an email. You do this once per computer. Use the email you will use for GitHub.

$ git config --global user.name "Asha Rao"
$ git config --global user.email "[email protected]"
$ git config --global init.defaultBranch main

These commands print nothing when they work. --global means "for every project on this computer". The last line makes new projects start with a branch named main. (Older versions of Git call the first branch master. Git's documentation says new repositories will use main by default from Git 3.0, which has no release date yet. Setting it yourself makes your projects match GitHub today.)

Step 2: Create a project and turn on Git

$ mkdir hello-git
$ cd hello-git
$ git init
Initialized empty Git repository in /home/asha/hello-git/.git/

mkdir makes a folder and cd moves into it. git init creates the hidden .git folder. Your path will look different on your computer. The folder is now a repository with no history yet.

Step 3: Make a file and ask Git what it sees

In a text editor (VS Code or Notepad is fine), create a file named hello.txt inside hello-git containing one line: Hello, Git. Then ask:

$ git status
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    hello.txt

nothing added to commit but untracked files present (use "git add" to track)

git status is the command you will type most. Read it like a report: you are on branch main, there are no commits yet, and hello.txt is untracked, which means Git can see the file but is not recording it. Git also tells you the next command to try.

Step 4: Stage the file, then commit it

$ git add hello.txt
$ git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file:   hello.txt

git add moved the file into the staging area. Status now says "Changes to be committed", which means: staged, not saved yet. Now save the snapshot with a message:

$ git commit -m "Add hello.txt"
[main (root-commit) 29194b2] Add hello.txt
 1 file changed, 1 insertion(+)
 create mode 100644 hello.txt

Read the first line: the commit went onto branch main, root-commit means it is the very first commit of the project, 29194b2 is its short ID, and the rest is your message. -m lets you write the message on the same line.

Step 5: Change the file and see the difference

Open hello.txt again and add a second line: This is my first repository. Then:

$ git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   hello.txt

no changes added to commit (use "git add" and/or "git commit -a")

The file is now modified: it differs from the last commit and is not staged. To see exactly what changed:

$ git diff
diff --git a/hello.txt b/hello.txt
index b7aec52..8de3847 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1,2 @@
 Hello, Git
+This is my first repository.

For now, look only at the last two lines. A line starting with + was added, and an unmarked line is unchanged. A - would mean a removed line. Part 6 explains the rest of this output.

Stage and commit it:

$ git add hello.txt
$ git commit -m "Describe the repository"

Step 6: Read your history

$ git log --oneline
99b5742 Describe the repository
29194b2 Add hello.txt

The newest commit is at the top. Each line is a short ID and its message. Without --oneline you see everything Git recorded:

$ git log
commit 99b5742cc3e72e3d2d38e8acd5f0055421e78271
Author: Asha Rao <[email protected]>
Date:   Sun Nov 1 05:08:51 2026 +0000

    Describe the repository

commit 29194b2a2352ce3ab3c991bf364679bf45b0378c
Author: Asha Rao <[email protected]>
Date:   Sun Nov 1 05:08:51 2026 +0000

    Add hello.txt

That is the whole basic loop: edit, git status, git add, git commit. Everything else in Git is built on it. Your IDs and dates will differ from the ones shown, which is normal.

Mistakes almost everyone makes

  • "nothing added to commit" or "no changes added to commit". You edited a file but forgot git add. Commit only saves what is staged.
  • "fatal: not a git repository". You are in the wrong folder. Use cd to move into your project, and pwd (print working directory) to check where you are.
  • A strange text editor opens when you commit. You left out -m "message", so Git opened an editor for the message. In the editor Vim press i, type the message, press Esc, then type :wq and press Enter. To abandon the commit, type :q! instead.
  • Vague messages such as "fix" or "changes". Future you will not remember what they meant. Write what you changed and why.
For the curious Going deeper: what git add really does

git add copies the file's current content into Git's object store and records it in the staging area. If you edit the file again after git add, the staged version is still the old one, and git status will show the file in both lists: staged and modified. Run git add again to stage the newer edit. git diff compares your working folder with the staging area, git diff --staged compares the staging area with the last commit, and git commit -a stages every already-tracked modified file for you, but never picks up new files.