git

Why would `git branch -d` result in "error: could not delete references: multiple updates not allowed"?


I have the following Git alias in my .gitconfig:

$ git md --help
'md' is aliased to '!: git merge && git merge --ff-only $1 && git branch -d $1'

Using it with a branch that has been already merged results in a weird error:

$ git branch t
$ git md t
Already up to date.
error: could not delete references: multiple updates for ref 'refs/heads/t' not allowed
error: could not delete references: 

(there is really nothing after the last colon).

Why does this happen, when there is only a single update taking place (git merge shouldn't touch the branch it is fast-forwarding to, AFAICS) and how to avoid it?


Solution

  • Your usage of $1 in the alias is wrong. Please see the docs at https://git-scm.com/docs/git-config#Documentation/git-config.txt-alias . The corrected alias should be IMO

    git config alias.md '!f() { git merge --ff-only $1 && git branch -d $1; }; f'