Version Control Systems (VCS)

  1. Local
  2. Centralized
  3. Distributed (Git, Mercurial)


  • Uses snapshots of the current states, not differences
  • Integrity: Every change in git is checksummed and it’s almost impossible to make a change without git knowing about it. (SHA-1)

Stages of files

All files tracked by git is always in one of these 3 stages:

  1. Modified
  2. Staged
  3. Commited

Sections in git

You can also call these areas (really no specific name for it)

  1. Working dir
  2. Staging area
  3. .git dir

Git Basics

A tiny tutorial + cheatsheet of most useful usefulnds in git


Find information about a git command.

git help <verb>
git <verb> --help

Git repository

  • Git repository is the .git folder. This is where git tracks all the changes and history

Create a repository

You have 2 options to start with a git repository, you can either

  1. Initialize an empty repo or
  2. Clone an existing one

1. Initialize an empty repo

  • Creates a skelton of a git repo
  • No files are tracked yet
git init

2. Clone an existing repo

  • Clones the entire repository to your local system
  • This will contain all the branches and change history of the codebase/repository
git clone

# or to clone into a specific folder

git clone my-folder

Note: Git has multiple transfer protocols (git://, https://, SSH)

Files in Git

  • All files are either tracked or untracked
  • Tracked files are those files git actually manages. These files go through the 3 stages of git files as discussed above
  • Git has nothing to do with untracked files. It is not tracked and is ignored by git. We can make use of .gitignore file to point git to the files which we do not want to track.

Git status

  • You can see which files are modified, staged, etc
  • Shows current status
git status

Git add

Add files to be staged for the next commit

git add <filename>


A file to specify which all file to be ignored or not ignored example:

# ignore all .a files

# but do track lib.a, even though you're ignoring .a files above

# only ignore the TODO file in the current directory, not subdir/TODO

# ignore all files in any directory named build

# ignore doc/notes.txt, but not doc/server/arch.txt

# ignore all .pdf files in the doc/ directory and any of its subdirectories

Git diff

Used to compare branches, commits, etc

  • If run without any arguments, It’ll compare working dir with staging
git add
  • If run with --staged compare staging to comitted

Git commit

  • Move staged to committed
git commit
  • inline message mode
git commit -m "Your commit msg here"
  • Skip staging area (Add all and commit)
git commit -a

Git rm

Stages the removal of the file

git rm --cached <filename>

(And add to .gitignore to make sure it’s not committed again)

Commit History

View the commit history

git log
  • View the changes made in each commit as well:
git log -p
# or --patch

Resources and Links