Why call git branch --unset-upstream to fixup?

后端 未结 8 1289
夕颜
夕颜 2020-12-12 09:42

I\'m more of a novice when it comes to advanced operations in git. I maintain my blog using the blogging framework Octopress. Though Octopress is not under any development s

相关标签:
8条回答
  • 2020-12-12 10:06

    delete your local branch by following command

    git branch -d branch_name
    

    you could also do

    git branch -D branch_name 
    

    which basically force a delete (even if local not merged to source)

    0 讨论(0)
  • 2020-12-12 10:16

    torek's answer is probably perfect, but I just wanted for the record to mention another case which is different than the one described in the original question but the same error may appear (as it may help others with similar problem):

    I have created an empty (new) repo using git init --bare on one of my servers. Then I have git cloned it to a local workspace on my PC.

    After committing a single version on the local repo I got that error after calling git status.

    Following torek's answer, I understand that what happened is that the first commit on local working directory repo created "master" branch. But on the remote repo (on the server) there was never anything, so there was not even a "master" (remotes/origin/master) branch.

    After running git push origin master from local repo the remote repo finally had a master branch. This stopped the error from appearing.

    So to conclude - one may get such an error for a fresh new remote repo with zero commits since it has no branch, including "master".

    0 讨论(0)
  • 2020-12-12 10:17

    For me, .git/refs/origin/master had got corrupt.

    I did the following, which fixed the problem for me.

    rm .git/refs/remotes/origin/master
    git fetch
    git branch --set-upstream-to=origin/master
    
    0 讨论(0)
  • 2020-12-12 10:19

    Issue: Your branch is based on 'origin/master', but the upstream is gone.

    Solution: git branch --unset-upstream

    0 讨论(0)
  • 2020-12-12 10:23

    This might solve your problem.

    after doing changes you can commit it and then

    git remote add origin https://(address of your repo) it can be https or ssh
    then
    git push -u origin master
    

    hope it works for you.

    thanks

    0 讨论(0)
  • 2020-12-12 10:26

    I had this question twice, and it was always caused by the corruption of the git cache file at my local branch. I fixed it by writing the missing commit hash into that file. I got the right commit hash from the server and ran the following command locally:

    cat .git/refs/remotes/origin/feature/mybranch \
    echo 1edf9668426de67ab764af138a98342787dc87fe \
    >> .git/refs/remotes/origin/feature/mybranch
    
    0 讨论(0)
提交回复
热议问题