[edit: added command outputs as requested, and reorganized for clarity]
I’ve got two clones of a particular repo checked out.
git log
commit e06424b5...
...
commit 557a0eb8...
shows the same thing in both, with same hash at the top.
git remote show origin
same in both
git branch
* master
still same in both
Now some differences.
From the ‘good’ clone:
git log origin/master..
commit e06424b5...
git show-ref HEAD
e06424b5... refs/remotes/origin/HEAD
# On branch master
nothing to commit (working directory clean)
From the ‘bad’ clone:
git log origin/master..
commit 557a0eb8...
git show-ref HEAD
557a0eb8... refs/remotes/origin/HEAD
git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
This is different [correction: earlier I reported that this output was the same]. show-ref seems to indicate that this checkout is one commit behind, while status says it is ahead. But git reset --hard e06424b5 changes nothing.
When I ask the ‘bad’ clone what it thinks needs to be pushed:
git diff --stat origin/master
it shows the files that were part of the e06424b5 commit, but in fact the only reason this checkout even has those files is because I pulled them.
Anyone know how to make the checkout realize that there’s nothing for it to push?
[edit: here are some additional commands and their outputs from the ‘bad’ clone…]
git log --graph --decorate --oneline
* e06424b (HEAD, master)
* 557a0eb (origin/master, origin/HEAD)
git rev-parse origin/master
557a0eb
git rev-parse HEAD
557a0eb (the previous hash)
e06424b (the correct, most recent hash)
Considering your comments, it seems to me that you are actually working in a ‘detached head’ mode.
The problem, is that your initial post implies that a branch is pointing to a specific place that you don’t want it to (This would be much more clear if you actually posted any of the output of the git commands you had run) in which case git reset –hard is what you would expect to do to fix this.
But in fact it seems that HEAD is just pointing to somewhere you expect it to not be, git checkout is the command you use to fix where HEAD is pointing to. I’m assuming that there may be something blocking the checkout from working, which is why I’ve added –force.
WARNING: using git checkout with the –force parameter may kill any uncommitted changes you have, or things of the like.
Assuming you have a master branch, it’s the one you want to checkout, and that it is in fact actually tracking origin/master, this should get you out of the pickle you have found yourself in.