在Git中删除本地分支和远程分支,可以使用git branch和git push命令。
删除本地分支的命令如下:
git branch -d <branch_name> 删除一个本地分支。
举例:
$ git branch -d feature # 删除本地分支feature
删除远程分支的命令如下:
- git push origin –delete 删除远程仓库origin上的分支。
- git push –delete 如果远程仓库名称不是origin,需要指定仓库名称。
举例:
$ git push origin --delete feature # 删除远程仓库origin上的分支feature
或者:
$ git push upstream --delete feature # upstream为远程仓库名称
如果本地分支与远程分支的名称不同,需要指定本地分支名称删除远程分支:
git push <remote_name> :<local_branch_name>
举例:
$ git push origin :feature_local # feature_local为本地分支名称,删除远程分支feature
删除本地分支feature同时删除远程分支feature的命令:
git push origin --delete feature && git branch -d feature