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?

Answer1:

a Git repository is made, by simplification, of <strong>3 kind of files</strong>:

<ol> <li>

<strong>Database-like objects</strong> ($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.

</li> <li>

<strong>repository-specific configuration and status</strong> ($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

</li> <li>

<strong>working copy files, or source</strong>: 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).

</li> </ol>

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.

人吐槽 人点赞

Recommend

Comment

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:git clone. How to clone local repo by hardlinks?