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?
-
1Doesn't this negate the point of git entirely? With hard links, you'd be editing the files in your master branch rather than editing a clone. – Polynomial Jul 04 '12 at 14:49
-
Have you read `git help clone`? This is actually the default behavior. – Fred Foo Jul 04 '12 at 14:51
-
Sure I did) But git clone -l do 'The files under .git/objects/ directory are hardlinked to save space when possible.' . But I need to hardlink all files. – Nikita Jul 04 '12 at 14:53
-
Polynomial, I aware of this. It's exactly what I need. – Nikita Jul 04 '12 at 14:54
-
Then you should not clone, but create a symbolic link of the repo – Antoine Pelisse Jul 04 '12 at 15:47
-
If you tell us exactly why you want such a cloned repo, I could decide whether advising you to do something like `cp --link --recursive` would be useful. E.g. if you are manipulating names of the file nodes in bulk — i.e. not using `git mv` — and would like to later bother with informing Git about all the renaming, while still keeping all the data associated with their old names. – can-ned_food Jul 12 '18 at 17:48
1 Answers
a Git repository is made, by simplification, of 3 kind of files:
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.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 designworking 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.

- 12,871
- 4
- 34
- 34