Branching and Merging are very powerful features in Git.
There are may branching strategies, my favorite is well explained at http://nvie.com/posts/a-successful-git-branching-model/
Pick any model you like and stick to it for a while to better understand and evaluate it. If you do not like that try another one.
In this model when we start to work on a new feature we
- Create a new branch (let’s call it feature) based on the develop branch and switch to it.
-
git checkout develop git branch feature git checkout feature
-
- Develop the new feature in the feature branch and add the changes to the repository.
-
git add . git commit -m "Feature is done in feature branch"
-
- Before merging the changes of the feature branch back into the develop branch get the latest changes from the develop branch, apply your changes on top of them and test the application
-
git rebase develop
-
- If there are merge conflicts, launch the Merge Tool. See Merging in Git with four panels in Windows to set up and use a great merge tool.
-
git mergetool
-
- It is possible that you will encounter merge conflicts in the same file multiple times. Just repeat the git mergetool command as many times as needed.
- When you are done with merging, complete the rebase
-
git rebase --continue
-
- Add and commit your changes in the feature branch
-
git add . git commit -m "Feature is tested in feature branch"
-
- When you have tested the code of the new feature, merge it back to the develop branch.
Switch back to the develop branch and merge the changes from the feature branch.-
git checkout develop git merge feature
-
- If there are any merge conflicts, Git will ask you to resolve them.