Last modified: August 22, 2025

This article is written in: 🇺🇸

What is Git?

Git is a version control system (VCS) created by Linus Torvalds, the same person who developed the Linux kernel. It’s a tool for tracking changes to files over time, mainly used in software development but useful for any project that involves evolving files.

The simplest way to think about Git is like a time machine for your project—it takes snapshots of your files at different points in time. You can revisit any of those snapshots later, compare them, or restore them if something breaks.

Git also helps teams work together without overwriting each other’s work. Two people can edit different parts of the same file at the same time, and Git can merge those changes into a single, consistent version.

In short, Git:

Branches in Git let you work on multiple versions of your project in parallel. For example, you might fix a bug on one branch while developing a new feature on another, switching between them as needed.

What is a repository?

A Git repository (often called a “repo”) is where Git stores your project files along with all the historical data that makes version control possible. This history lives inside a hidden .git folder. Without it, the directory is just a regular folder—Git won’t know it’s a repository.

There are two main kinds of repositories:

Git is distributed, meaning every local copy of a repository contains the full project history. Even without internet access, you can browse history, create commits, and roll back changes. You could lose the main server entirely and still restore the project from any local copy.

+-----------------+   +-----------------+   +-----------------+
|   Alice's Repo  |   |  Central Repo   |   |   Bob's Repo    |
|                 |   |  (e.g., GitHub) |   |                 |
|  o---o---o---o  |   |  o---o---o---o  |   |  o---o---o---o  |
+--------|--------+   +--------|--------+   +--------|--------+
         |                     |                     |
   Push/Pull           Push/Pull             Push/Pull
         |                     |                     |
+--------v--------+   +--------v--------+   +--------v--------+
| Local Workspace |   | Server Storage  |   | Local Workspace |
|                 |   |                 |   |                 |
|   o---o---o---o |   |   o---o---o---o |   |   o---o---o---o |
+-----------------+   +-----------------+   +-----------------+

Initializing a New Repository

To start tracking a new project with Git, you create a repository with:

git init project_name

This makes a new folder called project_name and adds an empty .git directory inside it. That .git directory holds all the metadata and history.

Example:

$ cd project_name
$ ls -a
.  ..  .git

If the .git folder is removed, Git no longer treats the folder as a repository.

What happens behind the scenes?

When you run git init, Git sets up the internal database it uses to track files, changes, and relationships between changes.

+-------------------------+
|         Git Repo        |
|                         |
|  +----------+           |
|  | .git dir |           |
|  +----------+           |
|                         |
|  +----------+  +------+ |
|  | Code     |  | Docs | |
|  +----------+  +------+ |
|                         |
|  +----------+           |
|  | Config   |           |
|  +----------+           |
|                         |
|  +----------+           |
|  | Hooks    |           |
|  +----------+           |
|                         |
+-------------------------+

Inside .git, you’ll find:

These pieces form a chain of snapshots. Git’s history browsing commands simply walk through these links to show you what changed and when.

Cloning an Existing Repository

To make a full local copy of a repository—its files, commit history, and configuration—you use the clone command. This is the standard way to download a project from a hosting service like GitHub, GitLab, or Bitbucket onto your own machine:

git clone https://github.com/djeada/git.git

When you run this, Git will:

  1. Create a new folder named git (matching the repository name, unless you specify otherwise).
  2. Download the entire commit history and all tracked files from the remote repository.
  3. Configure the local copy so it’s linked to the original remote, allowing you to pull updates or push your own changes later.

If you want to clone the repository into a specific directory rather than the default name, just provide the target path as the second argument:

git clone https://github.com/djeada/git.git /opt/projects

This places the full repository inside /opt/projects. From there, you can work with it like any other folder—but because it’s a Git repo, you can commit changes locally and sync with the remote repository when needed.

Verifying a Git Repository

If you’re unsure whether your current directory is part of a Git repository, there are two straightforward ways to check.

1. Use git status:

git status

On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

fatal: not a git repository (or any of the parent directories): .git

2. Look for the .git folder:

ls .git

If the directory exists and contains items like HEAD, config, objects, and refs, it’s a valid Git repository:

HEAD  config  description  hooks  info  objects  refs

If the .git folder is missing, Git isn’t initialized in that directory.

Table of Contents

    What is Git?
    1. What is a repository?
    2. Initializing a New Repository
    3. What happens behind the scenes?
    4. Cloning an Existing Repository
    5. Verifying a Git Repository