Renaming branches remotely in Git

后端 未结 9 1190
执笔经年
执笔经年 2020-11-28 17:07

If there is a repository that I only have git:// access to (and would usually just push+pull), is there a way to rename branches in that repository in the same

9条回答
  •  一向
    一向 (楼主)
    2020-11-28 17:45

    Adding to the answers already given, here is a version that first checks whether the new branch already exists (so you can safely use it in a script)

    if git ls-remote --heads "$remote" \
        | cut -f2 \
        | sed 's:refs/heads/::' \
        | grep -q ^"$newname"$; then
        echo "Error: $newname already exists"
        exit 1
    fi
    git push "$oldname" "$remote/$oldname:refs/heads/$newname" ":$oldname"
    

    (the check is from this answer)

提交回复
热议问题