要删除本地,首先要考虑以下三点

  • 列出所有本地分支
  • 搜索目标分支如:所有含有‘dev’的分支
  • 将搜索出的结果传给删除函数

所以我们可以得到:

    git br |grep 'dev' |xargs git br -d

本地新建了很多分支,比如

$ git branch
brabch
branch2
branch3
branch4
chucklu_zhCN
* master

其中以bra开头的分支都是临时性的分支,用完之后需要删除,使用命令逐个删除就太麻烦了

$ git branch |grep 'bran'
branch2
branch3
branch4

$ git branch |grep 'bran'|xargs git branch -d
Deleted branch branch2 (was a84d992).
Deleted branch branch3 (was 95a769c).
Deleted branch branch4 (was 9e7aecb).

$ git branch |grep 'bra'|xargs git branch -d
Deleted branch brabch (was e71cd6d).

参考资料:

Linux中的管道命令操作符 | http://www.cnblogs.com/chengmo/archive/2010/10/21/1856577.html

grep命令  http://www.cnblogs.com/peida/archive/2012/12/17/2821195.html

xargs命令 http://baike.baidu.com/link?url=9v3akR6obUlic6nkh5U4JBG4B7F3WsDxJOOUa_q3_b9ruseDhkcoIJ6rI5CzgP9h1kAXtVCM7g19VYM5_T6-cK

批量删除分支(包括本地和远端的)http://scriptogr.am/pison/post/git

Delete git branches whose name matches a certain pattern

 
 

Update: The -r option to xargs is a GNU addon. Unless you use xargs from GNU findutils it might not work. You can omit it but that leads to an error if the input piped to xargs is empty.


You can use git branch --list <pattern> and pipe it's output to xargs git branch -d:

git branch --list 'o*' | xargs -r git branch -d

Btw, there is a minor issue with the code above. If you've currently checked out one of the branches that begins with o the output of git branch --list 'o*' would look like this:

* origin_master
origin_test
o_what_a_branch

Note the asterisk * in front of the current branch name.

While you cannot delete the current branch anyway, it leads to the fact that xargs also passes * to git branch delete.

As I say it is just a cosmetic error, but if you want to avoid it use:

git branch --list 'o*' | sed 's/^* //' | xargs -r git branch -d

使用git批量删除分支的更多相关文章

  1. git批量删除分支

    要删除本地,首先要考虑以下三点 列出所有本地分支 搜索目标分支如:所有含有'dev'的分支 将搜索出的结果传给删除函数 所以我们可以得到: git br |grep 'dev' |xargs git ...

  2. Git批量删除

    Git批量删除 git的改动都需要stage过程后才能commit.当git中有大量改动时就需要能够批量操作在方便.改动分三种: modify: 有文件修改 add: 有文件增加 rm: 有文件删除 ...

  3. git远程删除分支但本地git branch -a仍能看到解决

    git远程删除分支但本地git branch -a仍能看到解决 在gitlab页面删除分支 但是本地能可以看到 $ git branch -a br_dev br_to_delete * master ...

  4. git 批量删除文件夹和文件

    git 批量删除文件夹和文件 硬盘删除文件后,执行$ git status   会提示你仍然需要$ git rm <文件>   此时如果是要删除大批量文件,这么一个一个命令下去不得累死人啊 ...

  5. git批量删除本地分支及远程分支

    1.批量删除本地分支 git branch |grep 'branchName' |xargs git branch -D git branch   查看本地分支 | grep 'branchName ...

  6. git 创建删除分支

    进入仓库目录 -- 查看本地分支 git branch -- 查看远程分支 git branch -r -- 查看远程和本地的分支 git branch -a -- 下载远程分支代码,并切换到分支 进 ...

  7. git批量删除文件和批量提交

    1. 单个删除文件: ① 通常直接在文件管理器中把没用的文件删了,或者用rm命令删了:(可选操作,可直接执行②删除) $ rm test.txt ② 确实要从版本库中删除该文件,那就用命令git rm ...

  8. git 批量删除本地分支

    git branch | grep 'bug' |xargs git branch -D

  9. git 批量删除 tag

    1. master分支存在大量冗余tag aa0e24dfd920a85c39da400a404309cb6fc69dc0 refs/tags/rc_69 f36f3f21f1ce61db3974e9 ...

随机推荐

  1. SAX方式解析XML文件实例

    books.XML文件: 书籍book.java实体类: public class Book { private String id; private String name; private Str ...

  2. iOS block的使用

    明明知道block是一个很重要的知识点,很久不用就又忘了,这是在网上看到的一个例子.(晚上回去整理另外的一个) 在视图A上有一个按钮(用来在点击的时候推出视图b)和一个label(用来显示从b传回来的 ...

  3. Action Filters for ASP.NET MVC

    本文主要介绍ASP.NET MVC中的Action Filters,并通过举例来呈现其实际应用. Action Filters 可以作为一个应用,作用到controller action (或整个co ...

  4. tomcat根据繁忙线程数对keepalive进行动态调整

    众所周知,Keep-Alive功能使客户端到服务器端的连接持续有效,当出现对服务器的后继请求时,Keep-Alive功能避免了建立或者重新建立连接.我们经常所用的tomcat服务器就支持HTTP Ke ...

  5. linux 和 windows下的程序计时

    Windows 使用<windows.h>中的GetTickCount(),该函数获得从操作系统启动到现在所经过(elapsed)的毫秒数,它的返回值是DWORD. 转自:http://w ...

  6. bat文件的妙用1-一键开启所有开发软件

    每天早上来的第一件事情,就是打开电脑,然后开一堆的软件 1.wamp 开发环境 2.钉钉   通讯工具 3.PHPstrom 开发工具 4.nodejs.bat Nodejs的扩展(node D:/w ...

  7. ubuntu下编译安装PHP

    首先配置configure // ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --wit ...

  8. 排序算法THREE:归并排序MergeSort

    /** *归并排序思路:分治法思想 O(nlogn) * 把数组一分为二,二分为四 * 四和为二,二和为一 * */ /** * 归并排序主方法 *@params 待排序的数组 *@params 初始 ...

  9. 今日吐槽20151208.net服务器控件

    正文 今天有个小任务是给页面添加一个搜索条件,复选框多选.因为页面都是服务器控件,我也只能用服务器控件配合了.然后给页面加了一个  CheckBoxList  控件.后台通过数据表加载数据. fore ...

  10. (用微信扫的静态链接二维码)微信native支付模式官方提供的demo文件中的几个bug修正

    native支付模式一demo(用微信扫的静态链接二维码)BUG修复,一共4个BUG 1.native_call_qrcode.php这个文件中的代码无法生存native支付的短地址2.WxPayPu ...