1

I'm working on two separate features, but as it turns out there is a lot of shared functionality. We're not in a position to refactor this out at the moment into a single library but I would like to re-use my code. The issue is both branches are in-progress and neither will get merged to our dev branch for a while. Switching branch back and forth (we use SourceTree around Git) means I never have both branches' code at the same time.

Other than some ugly "checkout A, copy code to a temp dir, checkout B" solution, what's a good way to handle this? Or is that as good a way as any?

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • Clone the other branch to a separate location, if you only need it for refernce? – Qumber Jun 15 '20 at 12:05
  • Does this answer your question? [How to selectively merge or pick changes from another branch in Git?](https://stackoverflow.com/questions/449541/how-to-selectively-merge-or-pick-changes-from-another-branch-in-git) – Greg Burghardt Jun 15 '20 at 12:17
  • Maybe consider using an additonal [worktree](https://git-scm.com/docs/git-worktree). Checkout B on the additonal worktree and work as normal on your main worktree with A checked out. – Romain Valeri Jun 15 '20 at 12:35
  • @GregBurghardt I guess that answers how to do it in that way... is cherry picking or merging the best approach though? – Mr. Boy Jun 15 '20 at 13:41
  • @RomainValeri I had not heard of that feature. I don't _think_ sourcetree app supports it and I don't want to mess it up and have to unpick things though! – Mr. Boy Jun 15 '20 at 13:42

1 Answers1

0

You might put the common code in its own branch/pr and then the separate stuff on separate branches/pr on top of the common stuff branch.

eftshift0
  • 26,375
  • 3
  • 36
  • 60