解决git远程分支已经删除本地还存在的办法

精选文章 2017年3月30日 15.09K

最近因为公司项目的需要在研究学习git,碰到个问题,我将远程分支直接删除了,在本地并有删除于是我用 git branch -a 还可以可以看到远程存在此分支。

  1. $ git branch -a  
  2.   master  
  3. * test  
  4.   remotes/origin/HEAD -> origin/master  
  5.   remotes/origin/master  
  6.   remotes/origin/newcarapi-test  
  7.   remotes/origin/test  

remotes/origin/newcarapi-test (其实是已经删除的,但是还是存在)

使用 git remote show origin 查看remote地址,远程分支,还有本地分支与之相对应关系等信息。

  1. $ git remote show origin  
  2. warning: redirecting to http://gitlab.xcar.com.cn/product_library/newcar-api.git/  
  3. * remote origin  
  4.   Fetch URL: http://gitlab.xcar.com.cn/product_library/newcar-api  
  5.   Push  URL: http://gitlab.xcar.com.cn/product_library/newcar-api  
  6.   HEAD branch: master  
  7.   Remote branches:  
  8.     gao.feifei                         new (next fetch will store in remotes/origin)  
  9.     master                             tracked  
  10.     refs/remotes/origin/newcarapi-test stale (use ‘git remote prune’ to remove)  
  11.     test                               tracked  
  12.   Local branches configured for ‘git pull’:  
  13.     master merges with remote master  
  14.     test   merges with remote test  
  15.   Local refs configured for ‘git push’:  
  16.     master pushes to master (fast-forwardable)  
  17.     test   pushes to test   (up to date)  

根据提示我们可以看到远程的已经不存在了,并且让使用(use ‘git remote prune’ to remove)此命令

  1. $ git remote prune origin  
  2. warning: redirecting to http://gitlab.xcar.com.cn/product_library/newcar-api.git/  
  3. Pruning origin  
  4. URL: http://gitlab.xcar.com.cn/product_library/newcar-api  
  5.  * [pruned] origin/newcarapi-test  

执行完命令后在次用 git branch -a 查看,可以看到已经被删除 (git branch -r 只查看远程的分子)

  1. $ git branch -a  
  2.   master  
  3. * test  
  4.   remotes/origin/HEAD -> origin/master  
  5.   remotes/origin/master  
  6.   remotes/origin/test  


关注微信公众号『PHP学习网

第一时间了解最新网络动态
关注博主不迷路~

PHP学习网:站内收集的部分资源来源于网络,若侵犯了您的合法权益,请联系我们删除!
分享到:
赞(0)

文章评论

您需要之后才可以评论
0点赞 0评论 收藏 QQ分享 微博分享

PHP学习网

PHP学习网