Avoiding conflicts

Overview

Teaching: 10 min
Exercises: 0 min
Questions
  • How should we organize branches to avoid conflicts?

Objectives
  • Avoid conflicts, avoid double work, avoid losing patches.

Avoiding conflicts


Develop separate features on separate branches

Common situation:


Wrong branch - what now?

Help! I made a commit to the “wrong” branch and it is a public branch and I was told I should not edit public commits, what now?

Solution: git cherry-pick the commit to the “right” branch:


Rewinding the local master branch

You made few commits to the local master branch. You then realize that it broke some tests but you have no time now to fix them. So you wish you had committed them to an experimental branch instead.

What now?

You want to move last three commits to a separate branch.

First make sure that your working directory and index are empty.

Then create a new branch (e.g. feature):

Now reset master back three commits:

$ git checkout master
$ git branch feature   # create feature branch but stay on master
$ git reset --hard c2  # on master

Another job well done. However, this should not be done if the commits have already been shared with others.


How do we correct public commits?


When is a good moment to merge?


Develop on feature branches

How to test combinations of features?

Key Points