What Git Clone REALLY Does (and why it matters)

/ Jack Lot


At its most basic, cloning is just a copy operation, but it does two other things behind the scenes that are worth understanding.

The .git folder

Git stores file history and repository metadata in a hidden folder called .git/. Clone creates this .git/ folder inside a new directory on your computer, then uses it to extract the latest versions of all your project files.

Remote references

Clone also links your local copy back to the original using remote reference pointers: bookmarks that keep track the state of the remote repository. When somebody contributes changes, any sync operation (like fetch, or pull) updates these pointers in your repository.

The cheatsheet

Cloning a repository

git clone <repository-url>

Pass the repository’s public SSH or HTTPS address to clone (usually listed its GitHub/GitLab hosting page). Clone downloads the repository and extracts it to your computer: both source code and history. This copy of the repository hosted on the internet is typically called a remote.

Listing remotes

git remote -v

During the clone operation, Git sets up special pointers that link your local repository to any remote counterpart. git remote -v lists these links.

Examining remote references

git branch --all

Lists all branches in your local repository, plus any remote tracking branches.

Going further

These remote reference pointers were, for me, the key to finally understanding how to handle merge conflicts that arose when I fetched changes from remote repos.

I go deeper on how they work in this post.


TAGS: videos, git