Merging pull requests - nrc-cnrc/EGSnrc GitHub Wiki

EGSnrc development occurs on feature branches, which upon review are merged into the develop branch. The develop branch is not officially released, but many users rely on it to work with the latest features, hence commits to develop should be considered permanent (or else corrected immediately).

Preparing to merge a feature branch into develop involves the following steps:

  1. Open a pull request to merge a feature branch into the develop branch.
  2. Request reviews and wait for approvals.
  3. Checkout the feature branch locally.
    git checkout feature-branch
    
  4. Rebase on the tip of develop; do not use the "Update branch" button, because this adds a useless merge commit:
    git rebase origin/develop
    
  5. Check that contributor names are added in the header of each modified file, e.g., using the following command:
    for f in $(git diff origin/develop --name-only); do 
        echo; 
        echo $f; 
        awk '/^...Author/,/^("|#)\s*("|)$/' $f; 
        awk '/^...Contributors/,/^("|#)\s*("|)$/' $f; 
    done
    
  6. Check that no end-of-line white space was inserted; grep them, or else git highlights them in the diff output:
    git diff origin/develop
    
  7. Check the C++ coding style, and run astyle if needed.
  8. Check commit message style and spelling.
  9. Reorder, reword, squash, delete, add or edit commits as needed:
    git rebase -i origin/develop
    
  10. Force-push feature branch and explain changes in the pull request conversation.
    git push --force-with-lease
    
  11. Wait for continuous integration (Travis-CI) check.

At this point the branch is ready for merging into develop. On github, there are three options in the merge button menu:

  1. Merge pull request keeps the side branch and creates a merge commit in the develop branch. Use this when it seems important to keep the history of the feature branch for future reference. Reserve this for larger changes with many logically independent commits. Don't use this for single-commit branches to avoid irrelevant merge bubbles. Always consider the next two options before creating a merge commit.

  2. Squash and merge combines all the changes on the feature branch into a single commit, and then adds this commit to the tip of the develop branch. This is useful when the feature branch contains a lot of small commits all related to one simple change, conceptually. For example, if one changes a variable name in many files, with one commit per file, then it would make sense to gather all these commits into one. Pay attention to edit and format the combined commit message accordingly.

  3. Rebase and merge takes all the commits on the feature branch, and simply adds them to the tip of develop (without squashing them together, and without creating a merge commit). This is useful when the feature branch ends up containing logically independent single commits that could in fact have been on separate feature branches. This occurs rarely in our feature branch workflow. For single commits, of course, it is equivalent to a "Squash and merge".