Refactoring your JavaScript Code — Part 2 — Merging Git Branches

Amanda Walker Brubaker
3 min readMar 12, 2021
Image Source

If you’re interested in learning how to create a Git Branch, I wrote about that in part 1 of this series.

Now that you have made your edits on a separate branch, you want to move those edits to another branch, in my case, back to my master branch. This is called merging. Merging is how Git allows you to integrate two independent lines of development (e.g. branches) and join them into a single branch.

Example Github repo showing multiple branches

My repo is live, but you might only have 2 branches rather than the 3 I have in the example above. All my edits are on the ‘refactor-branch’ and I want to merge them to my ‘master’ branch. If you want to compare your two branches, you can select the compare button in the bottom right of the image above.

How to Merge the Branches:

Note there are two images below that you should use a reference when going through these steps.

  1. In the last image above you’ll see a green ‘Compare & pull request’ button. Click it!
  2. Select the branch you want the edits to be moved to on the left, and the branch that has the current edits on the right of the top two light blue boxes in the image below. Note the red box with the arrow showing from refactor-branch to master.
  3. Confirm that it says Able to merge on the top line (red box on the right below)
  4. Write a Title for your merge. In my case I called mine “Merge edits from ‘refactor-branch’ to ‘master’
  5. Select the Create pull request in the bottom right of the image below.
  6. Confirm the top two red boxes in the second image below are accurate and then click Merge Pull Request
  7. Click the Confirm Merge button on the next page
  8. Celebrate! You should see a message that says something like “Pull request successfully merged and closed”
Github Repo of Two Branches Getting Merged
Confirming there are no conflicts between the branches before merging

That’s it! You’ve merged two branches!

If you have any questions or comments, feel free to comment below, and thanks for reading!

--

--