美文网首页
git删除远程分支

git删除远程分支

作者: 朽木自雕也 | 来源:发表于2018-03-05 12:08 被阅读13次

    最近公司项目不忙在网上买了一本《git学习指南》,系统的学习一遍git操作,这本书写得不怎么地,实话,很多方面第一没有讲到,遇到问题都是去网上观摩大神写的文章,不逼逼,说一个今天的问题删除远程分支
    命令整合一下
    列出本地分支:
    git branch
    列出远程分支
    git branch -r
    删除本地分支:
    git branch -D branchName
    其中-D也可以是--delete,如:
    git branch --delete branchName
    删除远程git服务器上的分支:
    git push origin -d branchName

    先创建一个分支并推送到远程版本库
    chenxuemingdeMacBook-Air:GitTest chenxueming$ git branch test
    chenxuemingdeMacBook-Air:GitTest chenxueming$ git push origin test:test
    Total 0 (delta 0), reused 0 (delta 0)
    To https://gitee.com/chenXueMing/GitTest.git

    • [new branch] test -> test
      查看远程分支创建成功
      chenxuemingdeMacBook-Air:GitTest chenxueming$ git branch -r
      origin/HEAD -> origin/master
      origin/develop
      origin/master
      origin/test
      你没看错,创建成功了。现在我要来删除远程分支
      chenxuemingdeMacBook-Air:GitTest chenxueming$ git push origin -d test
      To https://gitee.com/chenXueMing/GitTest.git
    • [deleted] test
      chenxuemingdeMacBook-Air:GitTest chenxueming$ git branch -r
      origin/HEAD -> origin/master
      origin/develop
      origin/master
      哎,竟然没问题,这尴尬了。我现在去git服务器把develop分支给删掉
    3月-05-2018 11-28-16.gif

    在来本地查看一下远程分支
    chenxuemingdeMacBook-Air:GitTest chenxueming$ git branch -r
    origin/HEAD -> origin/master
    origin/develop
    origin/master
    问题出现了,远程git库origin/develop分支已经删除掉了,但是本地查看远程库还存在尝试使用 git fetch 命令也没用
    chenxuemingdeMacBook-Air:GitTest chenxueming$ git fetch
    chenxuemingdeMacBook-Air:GitTest chenxueming$ git branch -r
    origin/HEAD -> origin/master
    origin/develop
    origin/master
    然后git help fetch,看到这样一个东西
    -p, --prune
    Before fetching, remove any remote-tracking references that no
    longer exist on the remote. Tags are not subject to pruning if they
    are fetched only because of the default tag auto-following or due
    to a --tags option. However, if tags are fetched due to an explicit
    refspec (either on the command line or in the remote configuration,
    for example if the remote was cloned with the --mirror option),
    then they are also subject to pruning.
    我英文不好,大概就是,删除不需要的远程跟踪。
    试了一下这个命令 git fetch -p ,挺管用的
    chenxuemingdeMacBook-Air:GitTest chenxueming$ git help fetch
    chenxuemingdeMacBook-Air:GitTest chenxueming$ git fetch -p
    From https://gitee.com/chenXueMing/GitTest

    • [deleted] (none) -> origin/develop
      再查看一下远程分支
      chenxuemingdeMacBook-Air:GitTest chenxueming$ git branch -r
      origin/HEAD -> origin/master
      origin/master
      结束

    相关文章

      网友评论

          本文标题:git删除远程分支

          本文链接:https://www.haomeiwen.com/subject/dugcfftx.html