Difficulty: beginner
Estimated Time: 25-30 minutes

git init / git config / git add / git commit / git ignore / git log / git status / git stash

Version control allows you to record changes to a file or set of files over time enabling you to go back to a specific version if required. Git is a Distributed Version Control System. This means that instead of having a snapshot of the latest files, you have a complete mirror of the repository on your local machine. The repository keeps track of the changes, when they occurred and who by. Having the complete repository on your local machine reduces delays due to network traffic and enables you to continue working when disconnected. The high level points this lab will cover are:

  • Initializing a new Git repo
  • Committing a modified version of a file to the repo
  • Common Git version control commands

By the end of this lab, you should be able to create a Git repo, use common Git commands, commit a modified file, view your project's history. This Scrapbook environment has been pre-configured with git installed. For more information on installing Git, please refer to the official documentation.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Git SCM - Lab 101

Step 1 of 5

Step 1 - Git Init

A Git repository is a virtual storage of your project. It allows you to save versions of your code, which you can access when needed. To store a directory under version control you need to create a repository. With Git you initialise a repository in the top-level directory for a project.

To create a new repo, you'll use the git init command. git init is a one-time command you use during the initial setup of a new repo. Executing this command will create a new .git subdirectory in your current working directory. This will also create a new master branch.

When a directory is part of a repository it is called a Working Directory. A working directory contains the latest downloaded version from the repository together with any changes that have yet to be committed. As you're working on a project, all changes are made in this working directory.


Populate a new project

We'll start off with just creating a simple project. Go ahead and create a README.md file. And add some content to the README.md

# Simple HTML Project

This is my first simple HTML project tracked by git.

Then another file called index.html with simple HTML content.

      Page title


My First Heading

My first paragraph.

These two files will form the initial release of our small project.

Initializing a new repository / git init

As this is a new project, a new repository needs to be created. Use;

git init

This command creates an empty Git repository - basically a directory called .git with subdirectories for objects, refs/heads, refs/tags, and template files. An initial HEAD file that references the HEAD of the master branch is also created. You will now have a .git directory, and you can inspect that with

ls .git/

This will reveal all the files and directory which construct the repository. For your new empty project, it should show you three entries, among other things:

  • a text file called HEAD, that has ref: refs/heads/master in it. This is similar to a symbolic link and points at refs/heads/master relative to the HEAD file.
  • a subdirectory called objects, which will contain all the objects of your project. You should never have any real reason to look at the objects directly, but you might want to know that these objects are what contains all the real data in your repository.
  • a subdirectory called refs, which contains references to objects.

Inspect the repository / git status

You can view which files have changed between your working directory and what's been previously committed to the repository using the command:

git status

The output of this command is called the "working tree status".


  • Running git init in an existing repository is safe. It will not overwrite things that are already there.
  • All files are "untracked" by Git until it's been told otherwise. The details of how is covered in the next step.