How to Git Merge a Branch into Master |Video upload date:  · Duration: PT12M19S  · Language: EN

A short practical guide to merging a Git branch into master with safe commands conflict handling and push best practices

If you want to merge a feature branch into master without turning version control into a soap opera, this guide walks you through the command line steps. You will learn how to update master, perform the merge, resolve conflicts, test locally and clean up branches. No drama, just git merge and a little common sense.

Update master

First make sure master matches the remote baseline that will receive the merge. This avoids surprises and angry CI pipelines.

git checkout master
# or
git switch master

git pull origin master

Pulling ensures your local master has the latest commits from origin. If you skip this, you might merge into an outdated history and then explain yourself to the team.

Merge the feature branch

Now bring the feature branch into master. You can merge while on master. Fast forward merges happen when master has no recent commits, which is Git being lazy in the best way.

git checkout master
git merge feature-branch

If you want to force a merge commit even when a fast forward is possible, use git merge --no-ff feature-branch. That preserves a visible branch point in history for posterity or for future archaeologists.

Resolve conflicts when they appear

Merge conflicts are not personal. They mean two changes touched the same lines. Learn the pattern and move on.

  • Run git status to list conflicted files.
  • Edit the files and remove conflict markers like <<<<<<< HEAD, =======, and >>>>>>>.
  • After resolving, stage the fixes and finish the merge with git add and git commit.
git status
# edit the files to resolve conflicts
git add .
git commit

If an automated merge tool helps you sleep at night, use it. If not, manual edits will do fine as long as you test afterward.

Test locally and push

Run unit tests, build steps and a quick manual check. If that passes, push master so others can enjoy your handiwork.

git push origin master

Pushing updates the remote and triggers CI if you have it. If CI fails, fix it on a branch and repeat the merge once green.

Clean up the feature branch

Once the branch has served its purpose remove it to avoid a cluttered repo that looks like a jungle after a developer convention.

git branch -d feature-branch
git push origin --delete feature-branch

Pro tips for less pain

  • Use pull requests on GitHub for peer review and to centralize discussion.
  • Consider rebasing a private feature branch on top of master before merging to reduce conflicts, but avoid rebasing shared branches.
  • Protect master in your repository settings so no one can force push or merge broken code without gates.
  • Keep commits small and tests green. This makes conflict resolution less tragic and more manageable.

That is the workflow. Update master, run the merge, handle conflicts, validate everything and clean up. Do this enough times and merging will feel like a predictable routine rather than a gamble. Now go merge something and pretend you had a plan all along.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.