Web Tutorials

How to Merge Branches?

In the previous web tutorials, we have discussed what branches are, how they’re made, what they do, and the different merging strategies. If you don’t know what any of these mean yet, go ahead and review these terms first and return to this tutorial.

How to merge to remote repository?

To merge to origin/master branch, you first need to create a new pull request. A pull request is a request to merge your feature branch to origin/master branch. To do this, go to your Git repository service provider (GitHub, Bitbucket, etc.) and go to your remote repository.

Here you are able to see the different actions you can perform under your remote repository. But for now, we’ll focus on creating a new pull request. Select the pull request option and fill in a description for your feature branch.

Here you have to create a description for your lead developer to know what your branch is for, what commits you’ve made, and what it does exactly. After completing the description, select the “Create pull request” button. To this point, it is up to your lead developer to merge your feature branch to the origin/master branch if he/she wants to.

The lead developer will have to review the files and source codes a contributor has made before merging to the origin/master branch. Then they have the ability to approve or disapprove the pull request. If your pull request has been accepted, it is up to the lead developer which merging strategy he/she will use to merge to the origin/master branch. If not, your lead developer will ask you to kindly review your code before requesting for another pull request.

Now your feature branch has successfully been merged to the origin/master branch.

How to merge to my local repository?

First, open your terminal/command prompt and go to your local repository. Then enter into the command line the following commands:

git fetch repository_name branch_name
git rebase repository_name/branch_name
git rebase master

Now your local repository is synced with your origin/master branch.

Check out my personal repositories here: GitHub & Bitbucket.

Leave a Reply

Your email address will not be published. Required fields are marked *