Git: warning: refname 'master' is ambiguous

前端 未结 5 2054
情书的邮戳
情书的邮戳 2020-12-07 17:15

I saw a few people asking the same question on here but it seems none of their advice is applicable to me. I\'m getting the warning that is in the title of this but I don\'t

5条回答
  •  情歌与酒
    2020-12-07 18:03

    For me I tracked down the source of this warning to much earlier when I incorrectly issued an "update-ref" command. If you forget to specify the full refs/heads/mybranchname path in the first arg, then a file .git/mybranchname gets created, which later leads to this warning when you try to switch to that branch.

    It is solved by simply deleting the .git/mybranchname, eg:

    rm .git/master
    

    And for reference, the correct form for the update-ref command is:

    git update-ref refs/heads/mybranchname mytargetbranch
    

    Don't forget the "refs/heads" part!

    Also, my most common use-case for update-ref is simply manually moving a branch to point to another commit, which I've found a simpler syntax to do:

    git branch -f myBranchToMove destinationBranchOrHash

    This syntax is easier for me because it doesn't require that error-prone refs/heads path qualifier.

提交回复
热议问题