Dan Berindei
Dan Berindei

Reputation: 7194

Git difference between @{upstream} and @{push}

Running this command shows both @{upstream} and @{push} references for all the branches in the local repository:

git branch --format '%(refname:short) [%(upstream:short)] [%(push:short)]' 

I noticed that some of my branches have both @{upstream} and @{push} set, some only have @{upstream}, and some only have @{push}.

@{upstream} matches the value of git config branch.<branch>.remote + git config branch.<branch>.merge, and running git branch --set-upstream-to=[remote/]other_branch updates it.

@{push} also includes the value of git config branch.<branch>.remote, if present, but I couldn't find a way to update the branch part.

Knowing that there's a single remote for both @{upstream} and @{push}, @{push} doesn't seem very useful, still I'm curious what its purpose is and how it can be updated.

Upvotes: 5

Views: 1050

Answers (1)

torek
torek

Reputation: 488453

@{push} is meaningful in what Git calls triangular workflows.

Suppose you have a repository with one upstream named fred that is a read-only place where you get updates from some group, and a second upstream named wilma that is a writable place where you can send a proposed update for that branch. Someone else will look at commits you send to wilma, and if they are approved, put them into fred.

In other words, the triangle looks like this:

fred     wilma
  *<------*
   \     ^
    \   /
     v /
      *
     you

You therefore wish to set up your branch feature to receive from fred but send to wilma. To do this, configure feature to have fred/feature as its upstream, and wilma/feature as its push target. feature@{push} now refers to wilma/feature while feature@{upstream} refers to fred/feature.

[Notes from @DanBerindei; see comment]: You can configure the push remote for all branches:

git config remote.pushDefault wilma

or only for the feature branch:

git config branch.feature.pushRemote wilma

You can not change the push branch name. You should instead use the current push strategy, so that the push branch name is the same as the local branch name (instead of the upstream branch name).

git config push.default current

Note: The @{push} suffix only works after the first push, even though the manual says it's "where we would push to".

Upvotes: 4

Related Questions