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

  • Queue build for non-default branch with git and VS
  • Visual Studio Tools for GIT - FETCH / PUBLISH vs PULL / PUSH
  • Find committer of a force push on github
  • git diff filtered by file name
  • Undo local changes interactive
  • Git branching strategy for a newly lean team
  • 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?

  • Output of git branch in tree like fashion
  • How can I move a single directory from a git repository to a new repository whilst maintaining the history?
  • How to manage one only key per each git repository?
  • Github rebase upstream/master with origin/master
  • Do I need a server to use git?
  • What's the svn revert equivalent in git?
  • 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.