Nikita
Nikita

Reputation: 857

git clone. How to clone local repo by hardlinks?

I have a local git repository. I want to clone it on the local machine by hardlinked files to save disk space. How can I do it?

Upvotes: 2

Views: 4607

Answers (1)

Antoine Pelisse
Antoine Pelisse

Reputation: 13099

a Git repository is made, by simplification, of 3 kind of files:

  1. Database-like objects ($GIT_DIR/objects): These objects are never modified, some can be added, some can be removed, but the files are never modified. It means that they can be exactly the same between many clones.

  2. repository-specific configuration and status ($GIT_DIR): These files contains configuration specific to the repository ($GIT_DIR/info/* for example). They also store the repository status, like what are the known branches, what is the checked-out branch, etc. They can't be shared between repository, or that would be against the design

  3. working copy files, or source: These files are most of the time your source code, they are meant to be different from one repository to another. They are flexible and change a lot (either because you code a lot, or because you switch branches a lot, or both).

As a matter of fact, the only non-changing, not repository-specific files are object files. And these are automatically hard-linked by Git if possible (even without specifying -l).

If you want two repositories on the same drive to have the exact same status and files, then you should definitely make a symbolic link. But you can't hard-link configuration and working copy files because they change too much and are specific to the repository.

Upvotes: 9

Related Questions