Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

My git version is Git-1.9.4-preview20140611 Earlier, I cloned an empty git origin repository. The repository cloned but with following message

warning: You appear to have cloned an empty repository. Checking connectivity... done.

Next, copied a .gitIgnore file which was in another project's master Git repository and committed it to the local master. This file has been used by us for many times before. This seems fine. We have a standardized .gitIgnore file for all our projects. This was created as part of best practices.

Next created a new branch and copied some code in the physical location where local git repo resides

git checkout -b FromCC

Added the code and committed in this branch.

git add --all
git commit -M "Blah"

All these operations are successful.

My purpose is to merge these changes eventually into local master branch.

I next do

git checkout master

and get following message.

Your branch is based on 'origin/master', but the upstream is gone. (use "git branch --unset-upstream" to fixup)

What does this message mean? Why would upstream 'go away' ?

Interesting observation: I repeated the same process with the same master Git repository today. This time the Git repository was not empty. It had .gitIgnore file before hand. This time fore-mentioned message did not appear.

like image 401
DolphinJava Avatar asked Jul 21 '14 16:07

DolphinJava


2 Answers

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.

like image 199
torek Avatar answered Oct 30 '22 14:10

torek


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.

like image 36
R. Maurer Avatar answered Oct 30 '22 12:10

R. Maurer