Under normal conditions, HEAD points to SHA1 (in this case, it is called disconnected) or points to an existing branch reference (in this case, the named branch is checked).
When you check new-branch ( HEAD points to refs/heads/new-branch ) and then somehow remove the new-branch , Git just removes the branch referencing file ( .git/refs/heads/new-branch ) and branch reflog file ( .git/logs/refs/heads/new-branch ). Git does not delete HEAD , nor does it update it to indicate in another place (for example, SHA1, which new-branch used to indicate), because it should not be necessary - you should not delete the current branch. Thus, HEAD still refers to the remote branch, which means that HEAD no longer indicates a valid commit.
If you then do git checkout -f master , Git update HEAD to point to refs/heads/master , a new entry is added to the HEAD reflog file ( .git/logs/HEAD ), the files are uploaded, and the index is updated. All this is normal - this is what Git always does when you check out another branch.
The problem you are encountering arises from how the reflog file is updated and how git reflog handles the updated reflog file. Each reflog entry contains "from" and "to" SHA1. When you switch from a non-existent new-branch to master , Git does not know what SHA1 is from. Instead of an error, it uses all-zeros SHA1 ( 0000000000000000000000000000000000000000 ). All-zeros SHA1 is also used when ref is created, so this last reflog entry makes it look like the HEAD just created when in fact it was never deleted. Apparently, the china git reflog stops reflowing when it encounters all-zeros of SHA1, even if there are more entries, so git reflog prints only one entry.
The following is shown:
$ git init test Initialized empty Git repository in /home/example/test/.git/ $ cd test $ echo hi >file1 $ git add file1 $ git commit -m "test commit 1" [master (root-commit) 3c79ff8] test commit 1 1 file changed, 1 insertion(+) create mode 100644 file1 $ git checkout -b new-branch Switched to a new branch 'new-branch' $ echo test2 >file2 $ git add file2 $ git commit -m "test commit 2" [new-branch f828d50] test commit 2 1 file changed, 1 insertion(+) create mode 100644 file2 $ cat .git/HEAD ref: refs/heads/new-branch $ cat .git/refs/heads/new-branch f828d50ce633918f2fcaaaad5a52ac1ffa1c81b1 $ git update-ref -d refs/heads/new-branch $ cat .git/HEAD ref: refs/heads/new-branch $ cat .git/refs/heads/new-branch cat: .git/refs/heads/new-branch: No such file or directory $ cat .git/logs/HEAD 0000000000000000000000000000000000000000 3c79ff8fc5a55d7c143765b7f749db4dd8526266 Your Name < email@example.com > 1411018898 -0400 commit (initial): test commit 1 3c79ff8fc5a55d7c143765b7f749db4dd8526266 3c79ff8fc5a55d7c143765b7f749db4dd8526266 Your Name < email@example.com > 1411018898 -0400 checkout: moving from master to new-branch 3c79ff8fc5a55d7c143765b7f749db4dd8526266 f828d50ce633918f2fcaaaad5a52ac1ffa1c81b1 Your Name < email@example.com > 1411018898 -0400 commit: test commit 2 $ git checkout -f master Switched to branch 'master' $ cat .git/logs/HEAD 0000000000000000000000000000000000000000 3c79ff8fc5a55d7c143765b7f749db4dd8526266 Your Name < email@example.com > 1411018898 -0400 commit (initial): test commit 1 3c79ff8fc5a55d7c143765b7f749db4dd8526266 3c79ff8fc5a55d7c143765b7f749db4dd8526266 Your Name < email@example.com > 1411018898 -0400 checkout: moving from master to new-branch 3c79ff8fc5a55d7c143765b7f749db4dd8526266 f828d50ce633918f2fcaaaad5a52ac1ffa1c81b1 Your Name < email@example.com > 1411018898 -0400 commit: test commit 2 0000000000000000000000000000000000000000 3c79ff8fc5a55d7c143765b7f749db4dd8526266 Your Name < email@example.com > 1411018898 -0400 checkout: moving from new-branch to master $ git reflog 3c79ff8 HEAD@ {0}: checkout: moving from new-branch to master
As you can see, HEAD reflog still has all the old entries - they just aren't showing git reflog . I believe this is a bug in Git.
Note: when you delete ref, the corresponding log is also deleted. I consider this a mistake, since there is no way to completely cancel the accidental deletion of links if you do not have a backup copy of the log.