DEV Community

loading...

GitHub: Merging a branch to Master

mariel
Dev. I love dogs, cookies, and learning new things.
Updated on ・2 min read

Today I had to google for the 508463460th time how to merge a branch to master, so here we go . . .

What the heck is a master?

The "master" branch is the default that is created when you create your repository. Next to your project name, you'll see the branch you're in. A screenshot of my terminal is below, with the branch in red:

The master branch is (supposed to be) the final, clean, working version. It should always be deployable - if this were a research paper, the master is what you're going to turn in for a grade.

Wait, where do I put the other stuff then?

The code that's not production ready goes in another branch. If you are going to be adding a new feature, fixing a bug, generally refactoring: that's what goes in other branches. They should have descriptive names, like filling-in-layout or add-login-feature. And then, ideally, what is in that branch is related to what the title is. If you're me, welp:
racoon jump fail

The point is that you should try and (allegedly) over time it'll get easier.

Why are there branches, is this a tree?

Yes. No. Sort of? Maybe. Think of the branches more as branches of a metro or subway. If we're using DC's WMATA, the orange line would be the master, and the others are various branches coming and going.

Okay but how do I actually do this?

Alright, to create a branch:

git checkout -b new-branch-name
git push origin new-branch-name
Enter fullscreen mode Exit fullscreen mode

So you create the branch locally, and then you push it to GitHub. From there you can commit and push as usual.

When you're done and ready to merge to master:

git checkout master
git merge new-branch-name
Enter fullscreen mode Exit fullscreen mode

TA-DA!

If you want/need more detailed information, you can start here.

Discussion (0)