fatal: Reference has invalid format: 'refs/heads/master~'

When I try any of these commands:

git branch
git branch -a
git pull
git log --pretty=format:"%C(yellow)%h%Cred%d\\ %Cblue[%cn]\\%Creset %s" --decorate --graph
git log --online --decorate --graph

I get the error

  • Git - coworker somehow overwrote my entire commit while resolving a conflict
  • git diff to see what a merge would introduce
  • Issues with git branch checkout due to untracked working tree files
  • Git Bash bash: open: command not found
  • How to create branch for the single file?
  • Why can't I push my new branch?
  • fatal: Reference has invalid format: 'refs/heads/master~'
    

    But the following commands work:

    git log --oneline --graph # removed --decorate
    git log
    

    Running

    find ./ -iname "*conflict*"
    

    doesn’t return any results.

    The output of find ./ -name "*master*" | grep "\./\.git" is

    ./.git/logs/refs/heads/master
    ./.git/logs/refs/heads/master~
    ./.git/logs/refs/remotes/origin/master
    ./.git/refs/heads/master
    ./.git/refs/heads/master~
    ./.git/refs/remotes/origin/master
    

    Don’t know if that helps, but I see master~ in there.

    Any idea what might be wrong? What other info can I provide you with?

  • Git workflow for Web Developer and Web Designer
  • How to view git log in Emacs?
  • How to see a merge history?
  • phpstorm git pull --rebase
  • How to show all repos one has access to on origin?
  • Cannot install openproject in Windows7 64 bit - undefined method `dlopen' for Fiddle:Module
  • 3 Solutions collect form web for “fatal: Reference has invalid format: 'refs/heads/master~'”

    It looks like some utility has created “backups” of the normal branch files (.git/refs/heads/...) with a trailing ~ character. This are not allowed branch names in Git as they would conflict with the suffix notation ...~N for obtaining ancestors.

    Commands that don’t need to query all refs (such as git log master without --decorate) are working but anything that tries to list all branches is choking on the invalid branch name.

    Simply delete the file ./.git/refs/heads/master~ (after backing it up) and you should be good to go.

    I think that your .git/HEAD file has invalid content. Check this file and if it has the tilde appended to the content remove it. For instance here on one of my repositories:

    $ cat .git/HEAD 
    ref: refs/heads/master
    

    Some of the files in .git are pointers to other references like this. Git reads them, dereferences the content and uses that as an object reference to go on with.

    It might be that the error is on the server side – so you should check that too.

    Delete your editor swap/backup files

    The files you have found are not related to git – they are created by an editor when opening the filename without the ~.

    Just delete them, and if you want to prevent this problem in the future just configure your editor to not create swap/backup files in the same directory as the file you are editing.

    Git Baby is a git and github fan, let's start git clone.