After reading the documentation, I still don't really understand what the
differences are between --shared
and --reference <repo>
. They seem so similar.
What are the differences between the
--shared
and--reference <repo>
options?Can they be used to save drive space when making multiple local clones of another local clone?
Can each local clone have a different branch checked-out?
Note: I'm aware that I can use multiple shallow clones with truncated
history by using git clone --depth <depth>
, but each clone still has to
duplicate at least some history in order to do that, so I was
thinking that maybe it's not the most optimal way to save drive space (though it
is better than nothing).
Background
Sometimes I like to have more than one checkout of my working copy in a repository, so I create multiple clones, where each clone has its own checkout.
However, I don't really need the whole history with each clone, just the most up-to-date versions of my branches, so I could possibly save a lot of drive space by having each clone use the tag, commit, tree, and blob objects from the original local clone (for example, via symlinks for something).
git clone
documentation
I checked the git clone
documentation to see if there's anything I
can use.
--shared
I saw that there's a --shared
option:
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.
This looks like it might be useful for helping me to save drive space with multiple clones that have different checkouts, since each clone shares objects with the original local clone.
--reference <repository>
Then I also saw the --reference <repository>
option:
If the reference repository is on the local machine, automatically setup
.git/objects/info/alternates
to obtain objects from the reference repository. Using an already existing repository as an alternate will require fewer objects to be copied from the repository being cloned, reducing network and local storage costs.NOTE: see the NOTE for the
--shared
option.
This says that it will reduce local storage costs, so this might be useful as well.