Repository
In short
A repository is the storage location for a project, holding all of its files plus the complete history of every change recorded by a version control system.
What is a repository in Git?
A repository, usually called a repo, is the home of a project under version control. It contains the project's files plus a record of every commit, branch, and tag, so you can see how the code has changed over time and recover any earlier version. In Git, this history lives in a hidden .git folder at the root of the project.
Git repositories come in two flavors. A local repository lives on your own computer, where you edit files and make commits. A remote repository is hosted on a server or a platform such as GitHub, GitLab, or Bitbucket, and it acts as the shared copy the team synchronizes with using git push, git pull, and git fetch. You create a new repository with git init, or copy an existing one, history included, with git clone.
A repository is like a library archive for a book that keeps not only the latest edition but every draft ever written, with notes on who changed what and why. Because Git is distributed, every clone is a complete repository with the full history, so work can continue even if the central server goes down.
People often use the word repository to mean the project page on a site like GitHub, but the repository is really the files plus their history, wherever they are stored. A repository is also different from a fork, which is a copy of someone else's repository under your own account. Package registries such as npm are sometimes loosely called repositories too, but they store published packages rather than source code history.
Key takeaways
- A repository stores a project's files together with their complete change history.
- Git keeps that history in a hidden
.gitdirectory. - Local repositories live on your machine; remote repositories are hosted for sharing.
git initcreates a new repository, andgit clonecopies an existing one.- Every Git clone is a full repository, not just a snapshot of the latest files.
Example
# Create a new, empty repository in the current folder
git init
# Or copy an existing remote repository, including its full history
git clone https://github.com/example/my-project.git
cd my-project
# List the remote repositories this clone is connected to
git remote -v
# Download new commits from the remote without changing your files
git fetch originReaders ask
What is the difference between a local and a remote repository?
A local repository is the copy on your own computer, where you make commits. A remote repository is hosted elsewhere, such as on GitHub or a company server, and you sync with it using git push and git pull.
What is the difference between cloning and forking a repository?
Cloning downloads a copy of a repository to your computer with git clone. Forking is a hosting platform feature that creates a copy of someone else's repository under your own account on that platform, which you then usually clone to work on.
What is a bare repository?
A bare repository contains only Git's history data, without a working copy of the files, and is created with git init --bare. It is typically used on servers as a central repository that people push to and pull from.
See also
- GitVersion Control, p. 10Git is a free, open-source distributed version control system that tracks changes to files over time, so developers can collaborate and undo mistakes.
- CommitVersion Control, p. 5A commit is a saved snapshot of a project's files in Git, recorded with a unique ID, an author, a timestamp, and a message describing what changed.
- BranchVersion Control, p. 2A branch in Git is an independent line of development that lets you work on a feature or fix in isolation, without affecting the main code until you merge it.
- ForkVersion Control, p. 9A fork is a personal copy of someone else's repository on a hosting platform, letting you experiment freely and propose changes back to the original project.
- .gitignoreVersion Control, p. 1A .gitignore file is a plain-text file listing patterns for files and folders Git should not track, such as dependencies, build output, logs, and secrets.
- MonorepoVersion Control, p. 31A monorepo is a single version control repository that holds the code for many projects, such as several apps, services, and shared libraries, managed together.
- Version ControlVersion Control, p. 39Version control is a system that records every change to a set of files, so you can see who changed what, return to earlier versions and work in parallel.
Spotted a mistake or something missing on this page?Suggest an edit