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
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)
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 clone
d 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".
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
Issue: Your branch is based on 'origin/master', but the upstream is gone.
Solution: git branch --unset-upstream
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
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