Search code examples
gitgit-pushgit-fetch

Which items from the local .git directory get copied to/from the remote upon pushing/fetching?


  1. When you push to a remote repository, which items from the local .git directory get copied to the remote .git directory?

  2. The same question in the opposite direction, when you perform fetch.


Solution

  • Basically two things get shared during fetch or push operations: objects and refs. Note that the receiving repo might store a given piece of information in a different file than where the sending server stored that piece of information.

    Objects include commits, "tree" objects (which represent content directories) and "blob" objects (which represent individual files of content), among other things. Together these make up your project's history. They are stored under .git/objects in either "loose" form (a file per object, in directories/files whose names are derived from the object's ID - which is the SHA hash of the object data) or "packed' form (in a file under .git/objects/packs). Transfers between repos use packed form, and it's up to the receiving repo to reorganize its packs if it sees fit.

    Refs are branches, tags, and other things; they provide "entry points' into history. These are stored in "loose" form under .git/refs or in packed form in a packed-refs file. Not only might a locally-loose ref end up packed on the receiving end, but depending on the refspec used to share the ref, the remote might update an entirely different ref (e.g. when fetching you typically update a tracking ref to match the remote's branch)