Configure upstream branch

Patrick Rachford
2 min readAug 15, 2022

--

Describes a configuration Git command

One Git command I’ve found to be extremely helpful is the push.default configuration setting. From the command line, you can set up your global default to depend on this configuration and save yourself time in the future when creating and pushing branches upstream in your repo.

Configure upstream branch

Upstream branches define the branch tracked on the remote repository by your local remote branch.

A lot of beginner guides teach users to use one of the following equivalent commands on push:

$ git push -u <remote> <branch>
$ git push-set-upstream origin/<branch>

This is great as it teaches users about the inner workings of upstream branches; however, users don’t think much in terms of going back and learning more about the Git process or ways to improve their workflow.

I believe these commands should be quickly followed up with how to configure upstream branches, so that the time to development is much quicker.

You can modify the default push setting in your git config with the following command:

$ git config --global push.default current

This configures Git to push the current branch to update a branch with the same name on the receiving end and removes the need to continuously name the origin and branch name. So that, git pushis equivalent to git push -u <remote> <branch>.

Other options include:

  1. nothing — do not push anything, unless a ref spec is explicitly given.
  2. current — push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.
  3. upstream — push the current branch back to the branch whose changes are usually integrated into the current branch. This mode only makes sense if you are pushing to the same repository you would normally pull from.
  4. simple — in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch’s name is different from the local one.
  5. matching — push all branches having the same name on both ends. This makes the repository you are pushing to remember the set of branches that will be pushed out.

For more information on about push.default, see the git-config documentation.

--

--