Difference Between Git Merge Master and Git Merge Origin/Master

John Wachira Jan 30, 2023
  1. the git merge origin/master Command
  2. the git merge master Command
Difference Between Git Merge Master and Git Merge Origin/Master

This article outlines the difference between the git merge master and git merge origin/master commands. We use both commands to integrate changes from the master branch.

The difference comes in when and how to use them, as we will discuss shortly.

We will define each command and go through its workflow. This will help us differentiate between the two.

the git merge origin/master Command

We use the git merge origin/master command to integrate upstream changes from the master branch to a local branch. The upstream master branch is the master branch in the remote repository.

Let’s look at an example.

To use the git merge origin/master, you will need to fetch from the remote repository. How do we go about it assuming our remote master branch is ahead of our local feature branch and we want to update the same?

First, we will run the git fetch command to fetch the changes from the remote repository.

$ git fetch

By running the below command, we can merge the changes from our remote master branch directly to our local feature branch.

$ git merge origin/master

Git merge origin master

It is a shorter route than the traditional one that involves pulling while checked out in the local master branch, switching to the feature branch, and merging the two.

the git merge master Command

As opposed to the git merge origin/master command, the git merge master command integrates changes from the local master branch. Let’s look at an example.

Assuming we have some relevant commit in our master branch but not present in our feature branch, how do we bring in these changes?

It is straightforward; we will use the git merge master command, as illustrated below.

First, we will switch to our feature branch.

$ git checkout feature

We can now merge the two branches.

$ git merge master

Git merge master

From the above, we can deduce that the git merge origin/master command is used to integrate changes from the remote master branch while the git merge master command integrates changes from the local master branch.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Merge