git push says "everything up-to-date" even though I have local changes


I have a remote gitosis server and a local git repository, and each time I make a big change in my code, I'll push the changes to that server too.

But today I find that even though I have some local changes and commit to local repository, when running git push origin master it says 'Everything up-to-date', but when I use git clone to checkout files on the remote server, it doesn't contain latest changes. And I have only one branch named "master" and one remote server named "origin".

PS: This is what git displays when running ls-remote, I'm not sure whether it helps

$ git ls-remote origin
df80d0c64b8e2c160d3d9b106b30aee9540b6ece        HEAD
df80d0c64b8e2c160d3d9b106b30aee9540b6ece        refs/heads/master
$ git ls-remote .
49c2cb46b9e798247898afdb079e76e40c9f77ea        HEAD
df80d0c64b8e2c160d3d9b106b30aee9540b6ece        refs/heads/master
df80d0c64b8e2c160d3d9b106b30aee9540b6ece        refs/remotes/origin/master
3a04c3ea9b81252b0626b760f0a7766b81652c0c        refs/tags/stage3


Are you working with a detached head by any chance?

As in:

detached head

indicating that your latest commit is not a branch head.

Warning: the following does a git reset --hard: make sure to use git stash first if you want to save your currently modified files.

$ git log -1
# note the SHA-1 of latest commit
$ git checkout master
# reset your branch head to your previously detached commit
$ git reset --hard <commit-id>

As mentioned in the git checkout man page (emphasis mine):

It is sometimes useful to be able to checkout a commit that is not at the tip of one of your branches.
The most obvious example is to check out the commit at a tagged official release point, like this:

$ git checkout v2.6.18

Earlier versions of git did not allow this and asked you to create a temporary branch using the -b option, but starting from version 1.5.0, the above command detaches your HEAD from the current branch and directly points at the commit named by the tag (v2.6.18 in the example above).

You can use all git commands while in this state.
You can use git reset --hard $othercommit to further move around, for example.
You can make changes and create a new commit on top of a detached HEAD.
You can even create a merge by using git merge $othercommit.

The state you are in while your HEAD is detached is not recorded by any branch (which is natural --- you are not on any branch).
What this means is that you can discard your temporary commits and merges by switching back to an existing branch (e.g. git checkout master), and a later git prune or git gc would garbage-collect them.
If you did this by mistake, you can ask the reflog for HEAD where you were, e.g.

$ git log -g -2 HEAD

While git push says "everything up-to-date", you still can technically push a detached HEAD, as noted in the comments by Jonathan Benn

 git push origin HEAD:main

You have to specify the destination branch, since the source is not a branch, and does not have an upstream target branch.

What should be in my .gitignore for an Android Studio project?

git revert back to certain commit [duplicate]