git 删除本地和远程分支

In most cases, it is simple to delete a Git branch. You'll learn how to delete a Git brach locally and remotely in this article.

在大多数情况下,删除Git分支很简单。 您将在本文中学习如何在本地和远程删除Git分支。

TL; DR版本 (TL;DR version)

// delete branch locally
git branch -d localBranchName// delete branch remotely
git push origin --delete remoteBranchName

何时删除分支 (When to Delete branches)

It is common for a Git repo to have different branches. They are a great way to work on different features and fixes while isolating the new code from the main codebase.

Git回购通常有不同的分支。 在将新代码与主代码库隔离的同时,它们是处理不同功能和修复的好方法。

Repos often have a master branch for the main codebase and developers create other branches to work on different features.

Repos通常为主要代码库提供一个master分支,而开发人员创建其他分支以使用不同的功能。

Once work is completed on a feature, it is often recommended to delete the branch.

功能上的工作完成后,通常建议删除分支。

局部删除分支 (Deleting a branch LOCALLY)

Git will not let you delete the branch you are currently on so you must make sure to checkout a branch that you are NOT deleting. For example: git checkout master

Git不允许您删除当前所在的分支,因此必须确保签出未删除的分支。 例如: git checkout master

Delete a branch with git branch -d <branch>.

使用git branch -d <branch>删除一个分支。

For example: git branch -d fix/authentication

例如: git branch -d fix/authentication

The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet.

-d选项仅在分支已被推送并与远程分支合并后才删除。 如果要强制删除分支(即使尚未推送或合并),请使用-D代替。

The branch is now deleted locally.

现在,该分支已在本地删除。

删除分支REMOTELY (Deleting a branch REMOTELY)

Here's the command to delete a branch remotely: git push <remote> --delete <branch>.

这是远程删除分支的命令: git push <remote> --delete <branch>

For example: git push origin --delete fix/authentication

例如: git push origin --delete fix/authentication

The branch is now deleted remotely.

现在,该分支已被远程删除。

You can also use this shorter command to delete a branch remotely: git push <remote> :<branch>

您还可以使用以下较短的命令远程删除分支: git push <remote> :<branch>

For example: git push origin :fix/authentication

例如: git push origin :fix/authentication

If you get the error below, it may mean that someone else has already deleted the 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'

Try to synchronize your branch list using:

尝试使用以下方法同步分支列表:

git fetch -p

The -p flag means "prune". After fetching, branches which no longer exist on the remote will be deleted.

-p标志的意思是“修剪”。 提取后,将删除远程上不再存在的分支。

翻译自: https://www.freecodecamp.org/news/how-to-delete-a-git-branch-both-locally-and-remotely/

git 删除本地和远程分支

git 删除本地和远程分支_如何在本地和远程删除Git分支相关推荐

  1. git 怎么备份本地分支_同步管理本地git仓库和github仓库上的分支

    参考文章 分支管理策略 在实际开发中,我们应该按照几个基本原则进行分支管理: 首先,master分支应该是非常稳定的,也就是仅用来发布新版本,平时不能在上面干活 那在哪里干活呢?干活都在 dev分支上 ...

  2. git删除分支_程序员必须要掌握的 Git 使用技巧

    作者:你喜欢吃青椒么链接:juejin.im/post/5d157bf3f265da1bcc1954e6 前言 本文是参考廖雪峰老师的Git资料再加上我自己对Git的理解,记录我的Git学习历程,作下 ...

  3. git如何切换分支_拜托,不要再问我Git分支如何使用

    今天来讲讲我使用Git分支的一些经验,记录一下,希望对大家有帮助. 阐述 在平常开发中,一般都会对应三种环境,本地环境.测试环境.线上环境.开发的基本流程都是先在本地环境开发好,再把代码发布到测试环境 ...

  4. 拉取远程分支到本地分支_保险公司在本地没有分支机构可以投保吗?异地投保会影响理赔吗?...

    保姐经常看到客户提出类似"我住的地方不在保险的销售区域,是不是不能投保这款保险?"."异地投保会不会被拒赔?"的问题,可见消费者对于"保险的销售区域是 ...

  5. svn比较本地与svn差异_如何从SVN差异中删除SVN属性

    svn比较本地与svn差异 I use SVN for my projects version control system. Sometimes I need to see the differen ...

  6. eclipse git 取远程代码_【JAVA】Eclipse中使用git进行pull远程代码

    当使用eclipse或者MyEclipse进行pull远程代码的时候,或者github的代码的时候报如下错误代码: 代表我们没有配置我们的Git地址,这里我教大家配置一下.首先下面是错误代码: The ...

  7. java 远程共享_【原创】(扫盲)远程共享对象SharedObject的用法

    学习fcs也有差不多一个月了,感觉最有特色的东西还是SharedObject. 今天就写个基本的教程关于它,第一次写教程(以前都是看教程-_-),手心都出汗了,心怕写得有错误导读者就惨了 , 斑竹有空 ...

  8. mysql拒绝远程连接_解决Mysql数据库拒绝远程连接和忘记密码的问题

    解决数据库忘记密码的问题 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 编辑m ...

  9. mysql 怎么登陆远程服务器_教你手机怎么远程连接云服务器

    图片来源网络侵删 01下载安装"微软远程桌面APP" 应用市场搜索"RD client",可以找到 02打开RD client,添加服务器 点击右上角的&quo ...

最新文章

  1. ArcGis For Flex 之 QueryTask地理坐标展现【原创】
  2. js操作cookie的函数
  3. centos下安装ruby,删除ruby
  4. Excel表格内容导出到页面
  5. linux怎么查看定时任务有没有运行,怎么看crontab定时任务是否执行
  6. 让AI自动调参,才是百度无人车的进化方式:适应环境全靠自己 | 论文
  7. PHP中静态(static)调用非静态方法详解--调用!!!
  8. 9本R语言书,从入门到进阶都在这了
  9. 掌握这三种方法!Word、PPT、Excel、JPG、PDF之间任你转换
  10. 基于人脸识别的门禁系统设计PPT汇报
  11. iPhone如何快速设置自定义铃声?苹果手机铃声设置教程
  12. Learning Affinity from Attention End-to-End Weakly-Supervised Semantic Segmentation withTransformers
  13. 做一篇美篇的计算机基础知识,怎么制作美篇-4个方法教你简单写出原创文章
  14. GIF录制神器--GIF123
  15. configure配置调试
  16. 【Javaweb】基础开发流程与介绍
  17. PPT封面反转镂空文字
  18. 数字图像处理第一二章
  19. 网络加速器是干什么用的?
  20. 基于Java毕业设计音乐管理系统源码+系统+mysql+lw文档+部署软件

热门文章

  1. SpringBoot—自定义线程池及并发定时任务模板
  2. QT 连接 sql server数据库 完整演示
  3. 掌握基于switch语句的流程控制测试分析 1221
  4. 01 能够使用Format实现格式化输出显示
  5. css标签的三种显示模式
  6. Zabbix检测Mysql的主从同步
  7. virtualbox ,centos 的多网卡如何设置
  8. Java实现升序排列的整形数组A,元素两两不相等找出A[i]=i的数据
  9. 释放技术红利 阿里云存储服务降价15%
  10. iOS25个性能优化,和内存优化