HOWTO · Git

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, providing clarity on their uses in version control. Learn how to effectively manage your Git repository by understanding these essential commands. Enhance your workflow and collaboration with this comprehensive guide tailored for developers at all levels.

On this page

git push origin master names the local master branch to push to the remote named origin. By contrast, git push origin omits a branch name, so the refs it pushes depend on push.default: simple pushes the current branch to its upstream when the required tracking and branch-name checks pass, while matching can push multiple local branches that have same-named branches on origin. Use the named command to select master; before using the branchless command, check its configured mode and the branches that mode selects.

Push a named branch with git push origin master

The command git push origin master explicitly selects the local branch named master and sends it to origin. The current checkout does not change that selection: running it while on feature still names master. The remote branch is updated according to the push refspec; this command does not imply that master is the project’s primary branch, and the branch name can be changed to another local branch name.

For example, git push origin feature explicitly selects feature. If the remote has no branch with that name, Git can create the remote ref as part of the push, provided the push is accepted by the remote. The command does not rely on the current branch’s upstream to choose its source branch.

Push the current branch with git push origin

With no branch argument, Git uses the configured push.default behavior; the command is not necessarily limited to the checked-out branch and does not always require that branch’s upstream. In simple mode, Git pushes the current branch to its upstream when one is configured and the branch-name checks pass. In matching mode, Git pushes local branches that already have same-named branches on the remote, so one git push origin can update multiple branches and does not select them by the current branch’s upstream. Check the configured mode with git config --get push.default and inspect branch tracking with git branch -vv before relying on a branchless push.

This self-contained example creates a local bare remote and a working repository, then pushes master by name and pushes the tracked current branch with git push origin. It sets configuration only in the temporary repository. The example is provided for you to run locally; no output is claimed here.

set -eu

root=$(mktemp -d)
trap 'rm -rf "$root"' EXIT
remote="$root/origin.git"
repo="$root/work"

git init --bare -q "$remote"
git init -q -b master "$repo"
git -C "$repo" config user.name "Example User"
git -C "$repo" config user.email "example@example.com"
git -C "$repo" config push.default simple
git -C "$repo" remote add origin "$remote"
printf 'first commit\n' > "$repo/README.md"
git -C "$repo" add README.md
git -C "$repo" commit -q -m "Add README"
git -C "$repo" push -q origin master

git -C "$repo" switch -q -c feature
printf 'feature work\n' > "$repo/feature.txt"
git -C "$repo" add feature.txt
git -C "$repo" commit -q -m "Add feature"
git -C "$repo" push -q --set-upstream origin feature
git -C "$repo" push -q origin

git --git-dir="$remote" for-each-ref --format='%(refname:short)' refs/heads | sort

Choose the right command

Command Branch selection What to check
git push origin master The named local branch master Confirm that master is the branch you intend to send.
git push origin with push.default=simple The current branch to its upstream, if tracking and branch-name checks pass Confirm the upstream, name check, and configured mode.
git push origin with push.default=matching Every local branch that has a same-named branch on origin; this may include several branches Review all matching branch names on the remote before pushing.

Choose the named form when you want to select one specific branch. Choose the branchless form only after checking push.default: simple selects the current branch and checks its upstream relationship, while matching can select multiple branches by name. If the result is unclear, inspect the current branch with git branch --show-current, branch tracking with git branch -vv, and the push mode with git config --get push.default before pushing.