开发者

Git : How to Create local repo with symbolic links to the Git main repo

开发者 https://www.devze.com 2023-03-30 09:21 出处:网络
I would like to create a Git repo in which the users can only pull the files from the Git repository and can never push into it. Since this data cloned into the remote repo needed not be modified, I a

I would like to create a Git repo in which the users can only pull the files from the Git repository and can never push into it. Since this data cloned into the remote repo needed not be modified, I am thinking of creating soft links to the main repo to save space (data will be duplicated among many users).

Can i create soft links in my local repo to the files in the remote repo when i do a Git clone?

e.g. with some variation on git clone <path>/gitrepo .

... where gitrepo is the main dir, and the command should create my local git repo with symbolic links pointing to the gitrepo. The version control should be maintained. Until i do a git pull, my local repo should be maintained, even if the main gitrepo has moved ahead. A git pull should recreate the symbolic links to point to the latest of the main repo.

I am seeking to replace ln -s with a "version 开发者_如何学运维controlled ln -s"

Thanks, RB


Git does this automatically, when cloning locally. From the manpage of git clone:

--local, -l

When the repository to clone from is on a local machine, this flag bypasses the normal "git aware" transport mechanism and clones the repository by making a copy of HEAD and everything under objects and refs directories. The files under .git/objects/directory are hardlinked to save space when possible. This is now the default when the source repository is specified with /path/to/repo syntax, so it essentially is a no-op option. To force copying instead of hardlinking (which may be desirable if you are trying to make a back-up of your repository), but still avoid the usual "git aware" transport mechanism, --no-hardlinks can be used.

Another interesting flag might be -s:

--shared, -s

When the repository to clone is on the local machine, instead of using hard links, automatically setup .git/objects/info/alternates to share the objects with the source repository. The resulting repository starts out without any object of its own.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号