Upstream gone message on switching back to an empty master branch?

I came across this after creating a completely empty repo on github and git cloned to local. Including the warning about an empty repo. Then a commit for a newly created local file gave the message regarding "upstream is gone".

To fix it and to use the remote upstream repo for this case:

git push -u origin master

  • This transfers the locally existing master to the remote github repo.
  • The -u switch to push does set the upstream (long version is --set-upstream) to the set on github.

Message is gone as the master branch now is also available on the remote repo.


It's not the upstream repository (origin itself) but rather the specific branch you cloned (master on origin) that is missing.

Moreover, git's message is misleading: the branch master on origin did not go away, it was never there. When you cloned the empty repository, it had no branches at all. It continued to have no branches. Hence, your local master, which was set to track origin/master, was (is) tracking a branch that did (does) not exist.

The message is meant more for a situation like this:

$ git clone ...
$ git checkout featureX   # track some feature branch
[go away for a week, come back]
$ git fetch -p            # update remote branches

where, during that week you were away, the featureX branch was deleted (presumably merged into its development line and then no longer needed). At this point you're on a local branch, featureX, set to track remote-branch origin/featureX, but there is no origin/featureX any more.

In this case, though, you have local branch master tracking origin/master when there is no origin/master yet. Once you create it (via the push that makes the repository non-empty), the problem will go away. This cropped up only because by default you start with master even if the remote is empty and does not actually have a master yet.