Skip to main content

Version control

What is a Repository?

Definition

A repository is the storage for a project's files together with its complete version history — in Git, the hidden .git directory inside the project folder.

Also known as: Repo

Repository in more detail

Cloning a repository copies not just the current files but every commit, branch and tag that came before them. In Git all of that lives in .git: the object database of commits, trees and blobs, the refs that name branches and tags, the index that stages your next commit, and the config that records where the remotes are. Delete that directory and you are left with an ordinary folder of files and no history at all.

A remote is simply another repository the local one knows how to talk to, conventionally named origin. Pushing and pulling synchronise commits between them; nothing about Git requires a central copy, though teams almost always designate one as canonical. A bare repository is one kept without a working tree, which is what a server hosts because nobody edits files there directly.

How many repositories a project should have is its own long-running argument. A monorepo holds many projects together, so a change spanning several of them is one atomic commit and one review, at the cost of tooling that has to cope with scale. Polyrepo gives each service its own repository and independent history, at the cost of coordinating changes that cross boundaries. Note also that the word is overloaded: a package repository such as npm or PyPI is a distribution server, not a version control repository.

Repository example

$ git init my-project      # creates my-project/.git
$ ls -a my-project
  .git   README.md   src/

Inside .git
  objects/    commits, trees and file contents, by hash
  refs/heads/ one file per branch, holding a commit hash
  refs/tags/  tags
  HEAD        which branch is checked out
  index       the staging area
  config      remotes, user settings for this repo

$ git remote -v
  origin  git@github.com:acme/my-project.git (fetch)
  origin  git@github.com:acme/my-project.git (push)

$ git clone <url>     # full history, not just the latest files

Repository — common questions

What is the difference between a local and a remote repository?
A local repository lives on your machine and holds the full history you can work with offline. A remote is another copy, usually hosted, that you push to and pull from so collaborators can exchange commits.
What happens if I delete the .git folder?
You lose all history, branches and remote configuration; the working files remain as an ordinary directory. Unless another clone or remote exists, the history is unrecoverable.
What is a monorepo?
A single repository holding multiple projects or services. It makes cross-project changes atomic and easy to review, but requires build and CI tooling that can handle a large tree and run only what a change actually affects.

Keep reading

Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.

Browse the A-Z glossary