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

  • 列出所有本地分支
  • 搜索目标分支如:所有含有‘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. Mysql 冷备份批处理

    @Rem Generate today date @echo wscript.echo dateadd("d",0,date)>GetOldDate.vbs @for /f ...

  2. 【html】【15】特效篇--分页

    下载参考: http://aspx.sc.chinaz.com/query.aspx?keyword=%E5%88%86%E9%A1%B5&classID=&page=1 实例:  h ...

  3. flexbox布局模式-- 浅谈

    简介 Flexbox,一种CSS3的布局模式,也叫做弹性盒子模型,用来为盒装模型提供最大的灵活性.今天主要从以下几个方面简单谈谈flex. 1 版本更迭 2 flex容器 3 flex项目 4 fle ...

  4. CAF(C++ actor framework)使用随笔(send sync_send)(二)

    a). 发完就忘, 就像上面anon_send 以及send #include <iostream> #include "caf/all.hpp" #include & ...

  5. 专题三、ArrayList遍历方式以及效率比较

    一.遍历方式 ArrayList支持三种遍历方式. 1.第一种,随机访问,它是通过索引值去遍历 由于ArrayList实现了RandomAccess接口,它支持通过索引值去随机访问元素. 代码如下: ...

  6. Chocolatey:Windows软件包管理器

    Chocolatey 2016-08-03 https://chocolatey.org/ Chocolatey是一个Windows软件包管理器,就像Nuget或者npm,或者说类似Linux上的ap ...

  7. 替换a链接的href和title

    新项目准备验收,客户检测网页有安全隐患,说是当前网页使用“http://”有风险,指定外部链接不用“http://”怎么整…… 后来想到用JS替换字符串去操作,找了半天总算找到合用的,最终是用JQ去更 ...

  8. javascripct数组

    定义数组 数组对象用来在单独的变量名中存储一系列的值. 我们使用关键词 new 来创建数组对象.下面的代码定义了一个名为 myArray 的数组对象: var myArray=new Array() ...

  9. JAVA 修改 JSESSIONID

    @Action("sidTest") public void sidTest() { HttpSession session = request.getSession(); Str ...

  10. win7定时任务

    最近某app有个小抽奖,每天点击太麻烦,想做个定时任务访问抽奖链接(带着cookie登录信息,即可抽奖成功) 刚开始做了php,最后发现部署在百度bae中没法做定时任务每天执行,后来换成了python ...