Git: How to merge your branch

This specific content was written 8 years ago. Please keep this in mind as it may be outdated and not adhering to best-practices.

gitIn this post I will show you four ways to merge your branch with the main branch, which we will call develop, of the project.

1. Merging on develop

git checkout develop

git pull origin develop

git merge yourBranch

This method is the most frequently used. It uses the recursive automatic merging method of Git to merge the changes of your branch upon the main develop branch.

2. Merging with rebase

git checkout yourBranch

git rebase develop

In this method you are applying the develop branch upon yourBranch. If there is a conflict in the process of merging the process stops and you must fix your conflicts manually which may be an advantage some developers. Moreover it does not produce a merge commit message, so it helps to keep the commit history clean.

3. Merging with pull on your branch

git checkout yourBranch

git pull origin yourBranch

git pull origin develop


4. Merging with stash (if you are using Atlassian Stash)

git stash

git pull origin develop

git stash apply

In this method you are saving your changes, compared with the latest code of develop, and you are updating the latest version of develop. Then you are applying those changes in the latest version of the develop branch



Giannis Kanellopoulos

Biography to be completed

More Posts