6

I have two git clones of same remote repository. I have created several stashes in clone A and now want to move those stashes to clone B.

[Clone A] ---- stashes ---> [Clone B]

One workaround I could think of is creating branch for each stash and push that branch to remote through Clone A, and then pull these branches into Clone B. But this is not I would prefer to do.

Could anyone suggest any easier and cleaner way (like copying) of doing it?

Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79

3 Answers3

1

You should be able to copy over .git/refs/stash for the latest stash and .git/logs/refs/stash for all others up in the stack. Actually you should even be able to pull refs/stash for the latest one I think.

But this will probably not work correctly, as the commit objects for the stashes will not be present in the copy target. You can maybe set up .git/objects/info/alternates so that missing objects will be searched in your A repository to make the copy work in the target.

You should probably use git worktree to have multiple worktrees for the same remote repository instead of multiple clones. You will save much space and I think you should be able to share the stashes.

Vampire
  • 35,631
  • 4
  • 76
  • 102
0

Many ways :

  • through ssh: add one repo as remote of the other, and push/pull directly betwen them,

  • copy the .git/ folder of Clone A somewhere on Clone B machine, and use this "local copy" of your Clone A as a remote for Clone B

  • push the commits in Clone A to the central repo, but not under branches (branches are stored in refs/heads/, if you push to say refs/cloneA/stash1, a default git pull from other people will not fetch these references)

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • To elaborate on your third bullet, here is an interesting answer by @sehe: https://stackoverflow.com/a/5248758/470749 I wish someone would clean that up and describe it better though. – Ryan Dec 22 '18 at 14:18
0

You could copy the stash as a patch file from original to the new location. You can apply the patches (not commit them) and then stash it in the new location. Here is a post about doing this. I just followed the steps of the top two answers and it works great. Just keep in mind that you any untracked files are not automatically included in the patch. Potentially you could just do a git add on the untracked file, create the stash, and then I would expect it to be a part of the patch (unconfirmed). Here is a link to the steps I am referring to: Export a stash as a patch.

Ironchef
  • 26
  • 4