Merging GitHub Branches

How to merge GitHub Branches

When you create a branch for a new feature with Git, you are ostensibly making a separate file (forking) that will have no larger effect on the main project file until you are ready to merge that branch. Merging is a means of putting forked files, or branches, back together. When you merge a branch into your main project file, you are fusing the two files and all their working code back into a single branch.

All feature branches have a commit in common with the main branch in their history.

“git merge”

Using the command git merge takes all commits from a secondary or tertiary feature branch and integrates it with the main working branch to form a consolidated history of commits. Git merge does this by identifying a common ancestor in the commit history of both branches (as shown above). This common ancestor commit is used by git to create a new merge commit that will fuse the differences of each branch into a singular sequence.

You must be on the receiving branch before merging. To merge secondary branches into your main branch you must be working on the main branch in your code editor. You can use the git status terminal command to see what branch you are currently on. If necessary, use terminal command git checkout main to switch to that branch.

Make sure that all branches are up to date by using terminal command git fetch on both main and feature branches, and then execute git pull on your main branch.

Once all of these steps are complete and you are on the main branch in your code editor, use git merge <feature-branch-name> to merge the given feature branch into your main branch.

I hope this was helpful and thanks for reading!

Further Reading and Sources




Full stack developer and stand-up comic.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

ScandiPWA Certification Program | Instruction

Bound And Foreground Services in Android, A step by step guide.

My Journey as an Andela Learning Community (ALC 2.0) Facilitator for Abia State

Life is a journey of twists and turns, peaks and valleys, mountains to climb and oceans to explore.

IMAP: new messages since last check

Design Patterns, TDD, and Best Practices Need to be Removed From Our Brains

Model of a human brain

What is Tableau Server Client (TSC)? Part 1

I hacked the in-game currency in an online game

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sam Hall

Sam Hall

Full stack developer and stand-up comic.

More from Medium

Web Developer Career Options

The Basics of Responsive Web Design

Languages of 2022, I think…

TIL: There is a lot more to JavaScript’s console interface than what we use