Search code examples
springgitintellij-ideaworkflow

Git with multiple changes


The current workflow for our developers is

  1. Create a new branch from develop for each bug
  2. Make your changes, and commit them
  3. Create a Pull request

The issue :

  1. I am working on bug 1, branch name develop_bug1 . I commit my changes in the file file1.jsp and create a PR

  2. I now start working on bug 2, branch name develop_bug2. I find out that changes need to be made in the same file file1.jsp as bug 1. When I checkout develop_bug2, my changes from develop_bug1 aren't present.

  3. What if I finish my changes for bug 2 and commit and create a PR? Will it overwrite changes for bug 1?

Not sure where to start


Solution

  • Changes on the two branches will not be present in the other branch or the develop branch until the two bug branches are merged. They are entirely separate ‘copies’ of the code.

    Because both involve changes to the same file (file1.jsp) there are going to be so-called merge conflicts, which need to be managed.

    Let’s assume that develop_bug1 is to be merged back into develop first (either because it is more urgent or because is has less changes).

    Step 1: Merge develop_bug1 into develop. There will be no conflicts.

    Step 2: Merge develop into develop_bug2. This is sometimes called rebasing. There will be merge conflicts which you will need to resolve. Your IDE will help you deal with the conflicts by selecting which version of each change to accept.

    Step 3: Merge the updated develop_bug2 (which now includes changes originating in develop_bug1) into develop. There will be no conflicts.