2

I've been working on a feature branch with another developer who is located remotely. We have completed our work on this branch and now want to merge it back into master. We've encountered quite a few conflicts. There are certain files that I have worked on and I know how to deal with these conflicts and there are certain files that he has worked on where he will know how to fix these conflicts.

My question is, is there any way that I can begin the merge, fix the conflicts that I'm capable of, then stash the feature branch remotely while still in a merge state? At which point he could take over and finish the merge? Normally we could just do a screen share but he is in a completely different time zone.

I'm using SourceTree and only somewhat familiar with using git bash.

Josh L
  • 1,412
  • 2
  • 18
  • 40

2 Answers2

0

The answer to this question really depends on how you are using git.

Assuming the files are not committed in the feature branch and you can stash them there I would use:

git stash --patch

  • This will interactively allow you to stash the files with conflicts that you need your co-worker to merge while leaving all the files that you know how to resolve. Then you can perform the merge on what you know how to resolve. When you are ready to merge the stashed changes I would use "git stash apply", so the versions you stashed would remain in the list.

  • My only concern would be that you both are working in a "dirty" directory and have not committed if you can stash the changes. If you both are to a stable state in your feature branch, I would suggest you commit your changes. Then when you merge with the master it will create conflict files which your co-worker can later resolve.

0

I think you could use git rerere to record your conflict solutions, hand them over to your co-worker, who can apply them and then solve the remaining conflicts.

To enable git rerere you first need to do git config rerere.enabled true. From then on, all your conflict solutions are recorded by git and applied if the same conflict occurs again. You can read more about that functionality here.

After enabling rerere you can start doing the merge and solve the conflicts you are capable of. When you are done call git rerere which will give you some output like this:

Recorded resolution for 'your-conflict.txt'.
Recorded preimage for 'co-worker-conflict.txt'

Where your-conflict.txt is the file in which you have solved the conflicts, while co-worker-conflict.txt is a file your co-worker needs to solve.

The conflict solutions are stored in the folder .git/rr-cache/. You can send the contents of this folder to your co-worker and he puts them in the same folder.

When he afterwards starts the same merge you did before, he will get output like this:

Resolved 'your-conflict.txt' using previous resolution.
Recorded preimage for 'co-worker-conflict.txt'

Meaning that your solutions to file your-conflict.txt have been applied and the solutions to file co-worker-conflict.txt are still missing. File your-conflict.txt will be in "unmerged" state, however all conflicts are solved and it can just be git added.

As I'm not 100% sure about the internals of the rr-cache folder, I would empty it before recording the solutions and also before applying your files to your co-workers repository. If you want to do this often, it might be an idea to share the rr-cache folder somehow, e.g. like explained in this answer.

Community
  • 1
  • 1
lucash
  • 1,982
  • 17
  • 25