Meaning of 'upstream branch' in rebase

1.7k views Asked by At

It seems to me that the phrase 'upstream branch' is ambiguous and appears to have two contexts.

  1. an upstream branch is one that is tracked by a local branch (see Git Branching - Remote Branches), and

  2. an upstream branch is something in the context of rebasing (see Git Branching - Rebasing).

'upstream' in (2) is displayed in the CLI help:

$ git rebase -h
usage: git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] [<upstream>] [<branch>]
   or: git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] --root [<branch>]
   or: git-rebase --continue | --abort | --skip | --edit-todo

The first one is clear to me but, for the life of me, I can't seem to wrap my head around what 'upstream' refers to in rebase. Furthermore, I've come across having 'multiple upstream branches', (git branch with multiple upstreams) which further confounds this conundrum.

It seems to me that this notion of 'upstream branch' needs some disambiguation in the git-scm.com documentation. This would go a long way towards making sense of such commands as:

$ git rebase --onto master server client

described in Git Branching - Rebasing, and

$ git rebase master server
1

There are 1 answers

1
isherwood On

Rebasing applies the commits made to a working branch to a branch that is or was an ancestor of that branch. If you think about the flow of an actual stream, an upstream branch is one that departed the current branch somewhere in the past.

Rebasing probably cannot apply to downstream branches, or those that have commits ahead of the current branch. For example, if you were to branch after doing some work, then check out the previous branch and attempt to rebase onto the second branch it wouldn't work.

So upstream really just refers to a branch that's part of the history of the current branch, and more specifically the branch onto which you intend to rebase. Local and remote are irrelevant.