avatarGiorgos Myrianthous

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1813

Abstract

k out to the branch you wish to merge into yours. Say this is branch <code>feature/feature_b</code>:</p><div id="0897"><pre>git checkout <span class="hljs-built_in">feature</span>/feature_b</pre></div><h2 id="f063">2. Pull updates from the remote repository</h2><p id="3bfd">Now we need to pull all the updates made to the remote branch:</p><div id="4044"><pre><span class="hljs-attribute">git pull</span></pre></div><h2 id="f049">3. Check out back to your own branch</h2><p id="4843">Now that you have pulled the latest version of the branch you wish to merge, you need to check out back to your own branch:</p><div id="54e0"><pre>git checkout <span class="hljs-built_in">feature</span>/feature_a</pre></div><h2 id="980d">4. Merge the other branch into yours</h2><p id="6fec">Finally, you have to merge the desired branch into yours:</p><div id="414f"><pre>git merge <span class="hljs-built_in">feature</span>/feature_b</pre></div><p id="9cf1">If the branch that you have attempted to merge into yours does not interact with any changes that you have already made, the merge should complete successfully. In a different situation, merge conflicts will be reported and you should resolve them before pushing the changes.</p><h1 id="f8d5">Using GitHub Desktop</h1><p id="9d9a">If for any reason, you want to use the UI in order to merge another branch into your branch, then simply follow the steps shown below.</p><ol><li>Click on “Current Branch”:</li></ol><figure id="549a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*svv6raqf-Ks7hIl9.png"><figcaption>Source: <a href="https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/syncing-your-branch#merging-another-branch-into-your-project-branch">GitHub docs</a></figcaption></figure><p id="9035">2. Click on “C

Options

hoose a branch to merge into branch-name”:</p><figure id="626f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*fD8TKiKby7fbE-ui.png"><figcaption>Source: <a href="https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/syncing-your-branch#merging-another-branch-into-your-project-branch">GitHub docs</a></figcaption></figure><p id="ba45">3. Click on the branch you want to merge:</p><figure id="412a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*klCypnMCLUsAG_Yq.png"><figcaption>Source: <a href="https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/syncing-your-branch#merging-another-branch-into-your-project-branch">GitHub docs</a></figcaption></figure><p id="4cec">4. Click “Push Origin”:</p><figure id="fb1c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*jE4BrMK1FTVUotZR.png"><figcaption>Source: <a href="https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/syncing-your-branch#merging-another-branch-into-your-project-branch">GitHub docs</a></figcaption></figure><h1 id="1ecf">Conclusion</h1><p id="c14a">In this article, we explored a way to merge another developer’s branch into yours. To do so, you simply need to follow the four steps. Recall that <code>feature/feature_b</code> reflects the branch you wish to merge into your branch named <code>feature/feature_a</code>:</p><div id="537e"><pre>git checkout <span class="hljs-built_in">feature</span>/feature_b git pull git checkout <span class="hljs-built_in">feature</span>/feature_a git merge <span class="hljs-built_in">feature</span>/feature_b</pre></div><p id="5bba">Additionally, we looked at how the same operation can be executed through GitHub’s Desktop interface.</p></article></body>

How To Merge Other Git Branches Into Your Own

Quickly merge branches using the command line or GitHub Desktop

Photo by dorota dylka on Unsplash.

In most development teams, every time a new feature or bug fix needs to be implemented, developers create a feature branch from the development branch. While an individual engineer is working on the feature implementation, other tickets are also progressing on different feature branches that can also be merged to the development one.

In most cases, branches being merged shouldn’t really affect the implementation of your own ticket. However, there are certain scenarios in which you might want to merge another feature branch into your own branch. Say another developer has fixed a bug that is also affecting your existing work and you have to merge the bug fix in order to further progress your branch.

In the steps below, I am going to discuss how you can achieve this either programmatically or by using Github’s UI.

Using the Command Line

To do so, you need to follow the four steps listed below. For the sake of this example, let’s assume that the branch of the other developer is called feature/feature_b and the branch you are currently working on is named feature/feature_a.

1. Check out to the branch you want to merge into yours

The first thing you should do is to check out to the branch you wish to merge into yours. Say this is branch feature/feature_b:

git checkout feature/feature_b

2. Pull updates from the remote repository

Now we need to pull all the updates made to the remote branch:

git pull

3. Check out back to your own branch

Now that you have pulled the latest version of the branch you wish to merge, you need to check out back to your own branch:

git checkout feature/feature_a

4. Merge the other branch into yours

Finally, you have to merge the desired branch into yours:

git merge feature/feature_b

If the branch that you have attempted to merge into yours does not interact with any changes that you have already made, the merge should complete successfully. In a different situation, merge conflicts will be reported and you should resolve them before pushing the changes.

Using GitHub Desktop

If for any reason, you want to use the UI in order to merge another branch into your branch, then simply follow the steps shown below.

  1. Click on “Current Branch”:
Source: GitHub docs

2. Click on “Choose a branch to merge into branch-name”:

Source: GitHub docs

3. Click on the branch you want to merge:

Source: GitHub docs

4. Click “Push Origin”:

Source: GitHub docs

Conclusion

In this article, we explored a way to merge another developer’s branch into yours. To do so, you simply need to follow the four steps. Recall that feature/feature_b reflects the branch you wish to merge into your branch named feature/feature_a:

git checkout feature/feature_b
git pull
git checkout feature/feature_a
git merge feature/feature_b

Additionally, we looked at how the same operation can be executed through GitHub’s Desktop interface.

Programming
Git
Software Development
Software Engineering
Coding
Recommended from ReadMedium