2

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?

6
  • 1
    Doesn'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 4, 2012 at 14:49
  • Have you read git help clone? This is actually the default behavior.
    – Fred Foo
    Jul 4, 2012 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 4, 2012 at 14:53
  • Polynomial, I aware of this. It's exactly what I need.
    – Nikita
    Jul 4, 2012 at 14:54
  • Then you should not clone, but create a symbolic link of the repo Jul 4, 2012 at 15:47

1 Answer 1

9

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.