Home‎ > ‎

Feature Branches and Develop

Feature branches are clean way of reducing code conflicts when multiple developers are working on the same project. They allow the developer to work in a space where things aren't being changed while they are working. This allows each developer to work on their code without having to worry that someone else will break it.

This guide assumes:
  • That you know what a branch is.
  • That you know how to checkout a branch.
  • That you know how to push and pull to a remote repository.
  • That you are working in SourceTree.
  • That you have a Develop branch in your repository.
There are three main tasks that you will need to be able to do to work with feature branches:
  • Start a feature
  • Update your feature
  • Finish your feature
Actions in each section are marked in bold for use as a quick reference with explanations of why or how beneath them. Using the built-in Git-Flow tool is a convenient way start and end features. This guide will cover how to keep up with feature branches and develop both with or without it.

Starting a Feature:

Checkout and pull the latest develop branch.
    • This ensures that your feature branch will begin with the most up-to-date material.
Select the Git Flow button, then select Start New Feature.
    • If you don't want to use the git flow tool you can also click the branch button at the top and name your branch feature/<your feature>. You will now have a local feature branch. The first time you push this branch git will ask you what you want to name the remote copy and create a remote tag for your branch.
Develop code here, commit and push as much as you want to your branch.

Staying up to date with develop:

Note: It is advisable that your preform this step periodically. This will cut-down the number of conflicts that you will have to review when you are ready to finish your feature.
Checkout your feature branch.
    • Do this by double clicking on it and making sure it is bold on the left pane. If you are working on a machine that has yet to checkout your develop branch, you can check out the remote copy(if you have pushed) by expanding the remotes section on the left hand side and double-clicking your branch.
Find the origin/develop branch in the history pane.
    • If you can’t find develop you may need to change the option that says “Current Branch” to “All Branches”
Merge develop into your feature. 
    • Do this by right-clicking the develop branch in the left hand pane and selecting "merge develop into current branch" or by by right-clicking origin/develop tag and selecting "merge." You will be prompted that you are merging develop into the current branch which is your feature branch. 
Resolve any conflicts. 
    • Depending on your changes, this step can be pretty straight forward. The only time that you will have to resolve conflicts is when you have changed something in your feature branch that was also changed by someone else on the develop branch. This typically occurs when two features that are being simultaneously developed share some overlapping code. To resolve conflicts select Actions > Resolve Conflicts. Keep in mind that “Mine” is your feature and “Theirs” is Develop.

Finishing your feature

When you arrive at the point where you are ready to add your feature into develop, your branch should essentially be a copy of develop that includes the new feature that you would like to add. We achieve this by following these last few steps: 

Make sure you have performed the above step immediately prior to adding you feature into develop.
    • We do this to update your feature branch with all the changes that happened on Develop while you were developing your feature branch. This essentially updates the copy of develop that lives in your feature branch. This is important to do right before you add your code to develop because it shifts the responsibility of resolving conflicts that comes from the new code onto the creator of that code.
Ensure functionality.
    • At this point you are about to add your new code to the group development environment. Adding broken or erroneous code will affect the development process of others so make sure that the code is doing what it was intended to do and is free of bugs and errors.
Add your feature into develop.
    Keep in mind that you are just adding your feature to your local copy of develop. You will need to push after these steps to update the remote copy of develop.  Adding your feature     
can be achieved in one of two ways depending on how you started it:
    Git Flow
    • If you used the Git-Flow tool to create your feature then finishing your feature is as simple as pressing the Git Flow button and selecting “Finish Feature”. If you are done with your branch and don't intend to work on your feature in the future then when SourceTree prompts you, check the “Delete Branch” option.
    Merge your feature into develop (Fast-Forward).
    • If you didn't use Git-Flow then you need to merge your branch into develop. To fast-forward develop(adding your feature):
      • Check out develop by double-clicking it in the left pane(it should be bold now)
      • Right-click the head of your feature branch and select merge or in the left hand pane right-click your feature and select "merge feature into current branch."
    • This step is called a fast-forward because develop and your feature branch are essentially the same minus the new feature code that you have in your feature branch. A fast forward is a special type of merge that essentially moves the develop tag so that it matches your feature tag. In SourceTree this action will look like any other merge as git decides which type of merge is needed behind the scenes.


Comments