问题
$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found.
$ git branch -d origin/bugfix
error: branch 'origin/bugfix' not found.
$ git branch -rd origin/bugfix
Deleted remote branch origin/bugfix (was 2a14ef7).
$ git push
Everything up-to-date
$ git pull
From github.com:gituser/gitproject
* [new branch] bugfix -> origin/bugfix
Already up-to-date.
How do I properly delete the remotes/origin/bugfix branch both locally and remotely?
回答
摘要
git push -d <remote_name> <branchname>
git branch -d <branchname>
note:在多数情况下,<remote_name> 是 origin
删除本地分支
git branch -d <branch_name>
git branch -D <branch_name>
- -d 是 --delete 的别名,只会在完全合并后才能被删除
- -D 是 --delete --force 的别名,无论是否合并,强制删除
- 如果你想删除当前你所在的分支,那么会直接报错
删除远程分支
git v1.7.0 ,可以使用如下命名:
git push <remote_name> --delete <branch_name>
等同于
git push <remote_name> :<branch_name>
从 v2.8.0 版本开始,可以使用 :
git push -d <remote_name> <branch_name>