Refactoring your JavaScript Code — Part 2 — Merging Git Branches
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.
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.
- In the last image above you’ll see a green ‘Compare & pull request’ button. Click it!
- 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.
- Confirm that it says Able to merge on the top line (red box on the right below)
- Write a Title for your merge. In my case I called mine “Merge edits from ‘refactor-branch’ to ‘master’
- Select the Create pull request in the bottom right of the image below.
- Confirm the top two red boxes in the second image below are accurate and then click Merge Pull Request
- Click the Confirm Merge button on the next page
- Celebrate! You should see a message that says something like “Pull request successfully merged and closed”
That’s it! You’ve merged two branches!
If you have any questions or comments, feel free to comment below, and thanks for reading!