8

Is there any way to share the history of a repository in git without having to clone the whole folder again? Something equivalent to Mercurial's

hg share project project-branch

https://www.mercurial-scm.org/wiki/ShareExtension

endavid
  • 1,781
  • 17
  • 42
  • hmmm, I don't know mercurial at all. I guess I understood that site to say that you wanted multiple working trees with one history. Is [this](http://stackoverflow.com/questions/6270193/multiple-working-directories-with-git) what you're looking for? It seems like the closest you can get with git – houtanb Nov 05 '15 at 15:23
  • Could you please elaborate on that "share" part for those gitsters not very familiar with Mercurial? I'll make a guess though. If you want to make another local repo and make some history from your existing repo available there, then use the fact Git is fine with fetching history from *local* repos -- just use `/path/to/local/repo` or `file:///path/to/local/repo` as your URL. Moreover, if the first form is used Git will use hardlinking, if available, to save space. – kostix Nov 05 '15 at 17:01

1 Answers1

9

If I'm understanding the documentation for hg share, the closest Git equivalent would be git worktree, a new feature in version 2.5:

Manage multiple working trees attached to the same repository.

A git repository can support multiple working trees, allowing you to check out more than one branch at a time. With git worktree add a new working tree is associated with the repository. This new working tree is called a "linked working tree" as opposed to the "main working tree" prepared by "git init" or "git clone". A repository has one main working tree (if it’s not a bare repository) and zero or more linked working trees.

I believe it's still in beta, and there is an explicit warning not to use it with submodules.

Running git worktree add ../some/path/ branch from a repository creates a new working copy with branch checked out at ../some/path/.

A longer overview of this new command can be found on GitHub's blog.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257