Git 分支管理

  1. 查看不存在对应远程分支的本地分支

    $ git remote show origin

    or

    $ git remote prune origin --dry-run

  2. 删除不存在对应远程分支的本地分支

    $ git remote prune origin

  3. 删除远程分支

    $ git push origin --delete <branch_name>

    or

    $ git push origin :<branch_name>

  4. 批量删除远程分支

    $ git branch --sort=committerdate | grep -v 'master\|developer' | xargs git push --delete origin

  5. 重命名本地分支

    $ git branch -m old_name new_name

  6. 备份Git分支

    1
    2
    3
    4
    5
    6
    7
    #!/bin/bash
    cd realibox;
    for remote in `git br -r | grep -v 'HEAD\|developer'`
    do
    git co -b ${remote:7} ${remote}
    #echo 'git co -b ${remote:7} ${remote}'
    done
  7. 分支排序

    $ git branch --sort=-committerdate

    $ git branch --sort=committerdate

    1
    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)
    1
    2
    3
    for k in `git branch | sed s/^..//`; do
    echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t"$k";
    done | sort -r