Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

merge

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.

like image 644
Brian Hong Avatar asked Oct 26 '25 06:10

Brian Hong


1 Answers

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).
...

like image 147
AD7six Avatar answered Oct 27 '25 22:10

AD7six