简体   繁体   中英

Git: find remote branches that are not merged into a specific remote branch

Finding local branches that is not merged into a specific local branch (develop) is by doing

git branch --no-merged develop

but then how can I find remote branches that is not merged into a specific remote branch? The purpose is to leave those unmerged branches locally while remove them remotely.

To list remote branches, use the -r flag, to reference a remote branch prefix with the appropriate remote name:

git branch -r --no-merged origin/develop
           ^^             ^^^^^^^ 

Tucked away in git branch's help is the description for that:

$ git branch --help
NAME
       git-branch - List, create, or delete branches

SYNOPSIS
       git branch [--color[=<when>] | --no-color] [--show-current]
               [-v [--abbrev=<length> | --no-abbrev]]
               [--column[=<options>] | --no-column] [--sort=<key>]
               [(--merged | --no-merged) [<commit>]]
               [--contains [<commit]] [--no-contains [<commit>]]
               [--points-at <object>] [--format=<format>]
               [(-r | --remotes) | (-a | --all)]                           # <----
               [--list] [<pattern>...]
       git branch [--track | --no-track] [-f] <branchname> [<start-point>]
       git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
       git branch --unset-upstream [<branchname>]
       git branch (-m | -M) [<oldbranch>] <newbranch>
       git branch (-c | -C) [<oldbranch>] <newbranch>
       git branch (-d | -D) [-r] <branchname>...
       git branch --edit-description [<branchname>]

DESCRIPTION
...
       -r, --remotes
           List or delete (if used with -d) the remote-tracking branches. 
           Combine with --list to match the optional pattern(s).
...

Try -a flag to see both local and remote branches: Try -r flag to see only remote branches (as by @phd's suggestion in comments)

Something like this:

git branch -a --no-merged origin/master

Or to see only remote branches:

git branch -r --no-merged origin/master

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM