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

最后都变了- 提交于 2021-02-18 05:13:31

问题


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.


回答1:


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.




回答2:


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.




回答3:


I had same error message with github. The actual problem was that I had not approved invitation to the repository. So the git thought I did not have the rights for the repo.



来源:https://stackoverflow.com/questions/24870145/upstream-gone-message-on-switching-back-to-an-empty-master-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!