What happens under the hood when you run git clone?
Last updated
git clone creates a new local repository, downloads the full object database from the remote, sets up an origin remote, and checks out a working copy of the default branch.
Initialize and connect: Creates a
.gitdirectory and registers the source URL as the remote namedorigin.Transfer objects: Fetches all commits, trees, blobs, and tags (usually as a packfile) into
.git/objects.Set up refs: Creates remote-tracking branches under
origin/*and a local branch tracking the remote's default (HEAD).Check out: Populates the working directory from the checked-out branch and writes the index.
- https://iissnan.com/progit/html/en/ch9_6.html
- https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols
- https://dev.to/zopdev/how-git-clone-really-works-a-deep-dive-into-gits-object-database-24j7
- https://medium.com/@mina.samir93/what-actually-happens-when-you-run-git-clone-an-inside-look-f2c0aac761aa