Skip to content

Commit 0c47e8d

Browse files
committed
Merge branch 'po/doc-branch' into maint
Doc update. * po/doc-branch: doc branch: provide examples for listing remote tracking branches
2 parents 747201d + 1fde99c commit 0c47e8d

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

Documentation/git-branch.txt

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ git-branch - List, create, or delete branches
88
SYNOPSIS
99
--------
1010
[verse]
11-
'git branch' [--color[=<when>] | --no-color] [-r | -a]
12-
[--list] [--show-current] [-v [--abbrev=<length> | --no-abbrev]]
11+
'git branch' [--color[=<when>] | --no-color]
12+
[-v [--abbrev=<length> | --no-abbrev]]
13+
[--show-current]
1314
[--column[=<options>] | --no-column] [--sort=<key>]
1415
[(--merged | --no-merged) [<commit>]]
1516
[--contains [<commit]] [--no-contains [<commit>]]
16-
[--points-at <object>] [--format=<format>] [<pattern>...]
17+
[--points-at <object>] [--format=<format>]
18+
[(-r | --remotes) | (-a | --all)]
19+
[--list] [<pattern>...]
1720
'git branch' [--track | --no-track] [-f] <branchname> [<start-point>]
1821
'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
1922
'git branch' --unset-upstream [<branchname>]
@@ -28,11 +31,15 @@ DESCRIPTION
2831
If `--list` is given, or if there are no non-option arguments, existing
2932
branches are listed; the current branch will be highlighted with an
3033
asterisk. Option `-r` causes the remote-tracking branches to be listed,
31-
and option `-a` shows both local and remote branches. If a `<pattern>`
34+
and option `-a` shows both local and remote branches.
35+
36+
If a `<pattern>`
3237
is given, it is used as a shell wildcard to restrict the output to
3338
matching branches. If multiple patterns are given, a branch is shown if
34-
it matches any of the patterns. Note that when providing a
35-
`<pattern>`, you must use `--list`; otherwise the command is interpreted
39+
it matches any of the patterns.
40+
41+
Note that when providing a
42+
`<pattern>`, you must use `--list`; otherwise the command may be interpreted
3643
as branch creation.
3744

3845
With `--contains`, shows only the branches that contain the named commit
@@ -153,10 +160,12 @@ This option is only applicable in non-verbose mode.
153160
-r::
154161
--remotes::
155162
List or delete (if used with -d) the remote-tracking branches.
163+
Combine with `--list` to match the optional pattern(s).
156164

157165
-a::
158166
--all::
159167
List both remote-tracking branches and local branches.
168+
Combine with `--list` to match optional pattern(s).
160169

161170
-l::
162171
--list::
@@ -322,6 +331,18 @@ $ git branch -D test <2>
322331
<2> Delete the "test" branch even if the "master" branch (or whichever branch
323332
is currently checked out) does not have all commits from the test branch.
324333

334+
Listing branches from a specific remote::
335+
+
336+
------------
337+
$ git branch -r -l '<remote>/<pattern>' <1>
338+
$ git for-each-ref 'refs/remotes/<remote>/<pattern>' <2>
339+
------------
340+
+
341+
<1> Using `-a` would conflate <remote> with any local branches you happen to
342+
have been prefixed with the same <remote> pattern.
343+
<2> `for-each-ref` can take a wide range of options. See linkgit:git-for-each-ref[1]
344+
345+
Patterns will normally need quoting.
325346

326347
NOTES
327348
-----

builtin/branch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
830830
strbuf_release(&buf);
831831
} else if (argc > 0 && argc <= 2) {
832832
if (filter.kind != FILTER_REFS_BRANCHES)
833-
die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
833+
die(_("The -a, and -r, options to 'git branch' do not take a branch name.\n"
834+
"Did you mean to use: -a|-r --list <pattern>?"));
834835

835836
if (track == BRANCH_TRACK_OVERRIDE)
836837
die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead."));

0 commit comments

Comments
 (0)