git如何删除本地和远程分支(git删除本地和远程分支的方法)

用两行命令删除分支

// 删除本地分支
git branch -d localBranchName

// 删除远程分支

git push remoteName --delete remoteBranchName

git push origin --delete origin/zkx 错误的,应该为git push origin --delete zkx,remoteBranchName不用加上remoteName

本地删除分支

当一个分支被推送并合并到远程分支后,-d 才会本地删除该分支。如果一个分支还没有被推送或者合并,那么可以使用-D强制删除它。

远程删除分支

使用这个命令可以远程删除分支:git push <remote> --delete <branch>

你也可以使用这行简短的命令来远程删除分支:git push <remote> :<branch>

如果你得到以下错误消息,可能是因为其他人已经删除了这个分支。

error: unable to push to unqualified destination: remoteBranchName The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to 'git@repository_name'

使用以下命令同步分支列表:

git fetch -p

-p 的意思是“精简”。这样,你的分支列表里就不会显示已远程被删除的分支了。

未经允许不得转载:国外服务器评测 » git如何删除本地和远程分支(git删除本地和远程分支的方法)