Skip to content

Git操作 删除分支

bin4xin edited this page Apr 29, 2022 · 1 revision

删除远程和本地分支

  • 先查看需要删除的分支
> git branch -a
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/about
  remotes/origin/gh-pages
  remotes/origin/main
  remotes/origin/master
  • 我们这里需要删除masterabout分支:

TIPS:

当然如果你还在一个这个分支上时,那么 Git 是不允许你删除这个分支的。所以,请记得退出分支: git checkout main

> git push origin --delete about
To https://github.com/Bin4xin/bin4xin.github.io.git
 - [deleted]         about

> git push origin --delete master
···
 - [deleted]         master
  • 查看效果:
> git branch -a                  
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/gh-pages
  remotes/origin/main
  • git branch -d localBranchName命令来删除本地的分支
    • git branch -d about && git branch -d master

TIPS:

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同步分支;