A Simple Introduction to Git

This short read is meant to give you a quick introduction to Git and, hopefully, motivate you to learn more and use it for your work!

What is Git?

Git is an open-source distributed version-control system for tracking changes in any set of files. also allowing multiple contributors to collaboratively develop code.

Open-source – Git is a free and open source software. So anyone is freely licensed to use, copy and change the software in any way.

Version-control – It is a system that allows you to keep track of changes made to any file or set of files such that you can return to any of the prior states, if needed.

Distributed – All files of a project stored on a server computer, along with every change history, is copied to a local machine. After that, the local copy can be modified by an individual contributor to add more functionality, fix bugs, etc. With multiple contributors for a project, each have their own copy of all files on their local machine. You can easily restore a project from the server, if you happen to lose your copy on the local machine.

How does Git work?

Git basically takes a snapshot of what all your files look like at that moment and stores a reference to that snapshot.

Git has 3 main stages in Local

  • Working directory – You modify files in your working tree, on your local machine
  • Staging area – You selectively stage just those changes you want to be part of your next commit. It then adds only those changes to the staging area.
  • Local repo – You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory

Remote is the server machine that allows you to host your code in the cloud and collaborate with other contributors. There are some popular providers like GitHub and BitBucket, where you can host open-source code for free and private code for a fee.

working tree – Git, like many other version control systems, allows you to create branches, but stands out by making it extremely efficient and lightweight. Branching means you diverge from the main version of the code (called “main branch”), to make your changes, hence not affecting that main code. At any given point, you are in either the main or one of the branches – “working tree”.

How do I use Git?

The most direct and fastest way to work with Git is through the command line. You will be able to use all Git commands via the command line. However, it requires you to be familiar with some basic commands for the Terminal on a Mac, or Command Prompt on Windows.

There are also alternatives with a Graphical User Interface for Git, that provide a subset of the functionality for simplicity, like GitHub Desktop, SourceTree, etc.

The most commonly used Git commands are?

CommandsFunctionality
git clone <repo>Copy project from server to local machine
git addStart tracking file(s) for changes
git commit -m <desc of changes>Save modifications with a brief note
git pushCopy saved changes to file(s) from local to server machine
git pullCopy latest version of file(s) from server to local machine
git statusSummary of file(s) being tracked by git
git checkoutUndo changes made to file(s)
Commonly used Git commands
  • git clone <repo>

Create a copy of a repository (a project) from the server machine to a local machine.

  • git add <file name>

Tell Git to start tracking any changes to the file, adding them to a staging area. Alternatively, you can use git add . to let Git to track any changes to all files within the current folder directory on your local machine.

  • git commit -m <desc of changes>

“Save” changes made to a file/set of files in your staging area. Use -m option to write a meaningful commit message, briefly explaining the modifications made to the file. This would be of tremendous help for anybody to understand the changes, without having to read through the entire file.

  • git push

Copy the saved changes to the file(s) from local machine to the server machine. In addition, if you made the changes in a branch, the branch will be copied to the server as it is, for you to later merge to the main branch.

  • git pull

Copy the latest version of the files from server to the local machine.

  • git status

A summary of file(s) that are being tracked and/or committed on your local machine.

  • git checkout <file_name>

Undo and revert changes made to a file, to reflect the version as copied from the remote machine.

Where can I learn more?

This free ebook is a great reference for Git. 

For GitHub or BitBucket

Git cheatsheet.


In this simple introduction to Git, you learned what Git is, it’s basic functionality, how to use it, commonly used commands and additional pointers to learn more.

More about the author Harish Gante