简体   繁体   中英

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

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?

eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM