Difference Between Git Push Origin and Git Push Origin Master

John Wachira Sep 28, 2022
  1. the git push origin master Command
  2. the git push origin Command
Difference Between Git Push Origin and Git Push Origin Master

This article outlines the differences between the git push origin and git push origin master commands. We use these commands to push changes to the remote repository.

The difference comes in how and when to use them, as discussed below. We will cover what each command does, how to use it, and when to use each of the two commands.

the git push origin master Command

The git push origin master command is pretty straightforward. We use this command to push local changes from the master branch to the remote master branch.

This is its default behavior, and it cannot be changed.

That is all. There is not much that can be said about the command. Let’s move on to the next command.

the git push origin Command

The git push origin command is rather complicated than the previous command. Before Git version v1.7.11, the git push origin command was used to push all local branches to their corresponding remote branches.

Git version V2.0+ requires us to configure push.default to either matching or simple. When not set, Git defaults to the simple configuration, which will only push the current branch to the corresponding remote-tracking branch.

The command will fail if the local branch does not have a remote-tracking branch. Let’s look at an example.

Assuming we have a feature branch in our local repository and it has a remote-tracking branch, what happens when we invoke the git push origin command without setting the push.default value?

$ git push origin

Git will give you a warning, such as the one below.

Git warning

The output will be:

git push origin

As seen from the output above, Git has used the simple configuration, which has only pushed our feature branch to the remote repository.

What happens if we set the push.default value to matching? Let’s find out.

$ git config --global push.default matching

On running the git push origin command, we will get:

git push origin matching

We can see that Git has pushed two branches to the remote. (i.e., master and feature branches)

In a nutshell, the git push origin master will only push the master branch to the remote tracking master branch. On the other hand, the git push origin command will push the current local branch, provided it has a remote tracking branch.

However, the behavior of this command can be changed by setting the push.default value to matching to push all local branches to their corresponding remote-tracking branches.

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 Push