Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the format of <pattern> in git-branch --list

Tags:

git

As title, I have read the manual but in vain.

What I found is that a * can be wildcard pattern matching.

git branch --list 'issues*6'  issues/586  issues/616 

However, it's found by myself instead of mentioned in manual page.

I wonder what is the real format of <pattern>.

like image 611
Weihang Jian Avatar asked Dec 30 '16 22:12

Weihang Jian


People also ask

How many types of branches are there in git?

The two primary branches in Git flow are main and develop. There are three types of supporting branches with different intended purposes: feature, release, and hotfix.

What is git branch command?

The git branch command lets you create, list, rename, and delete branches. It doesn't let you switch between branches or put a forked history back together again. For this reason, git branch is tightly integrated with the git checkout and git merge commands.

What is branch name in git?

In Git, branches are commonly used in order to have a development separated from your main workflow. In software engineering teams, it is quite common to have a specific workflow implemented. You may choose for example to have one branch per major release or to have a branch in order to quickfix an issue.

How to list all branches of a git repository?

How to list branches in Git? The command to list all branches in local and remote repositories is: $ git branch -a If you require only listing the remote branches from Git Bash then use this command:

How do I change the name of a branch in Git?

Without -f, git branch refuses to change an existing branch. In combination with -d (or --delete ), allow deleting the branch irrespective of its merged status. In combination with -m (or --move ), allow renaming the branch even if the new branch name already exists, the same applies for -c (or --copy ).

How do I merge two branches in Git?

When creating a new branch, set up branch.<name>.remote and branch.<name>.merge configuration entries to mark the start-point branch as "upstream" from the new branch. This configuration will tell git to show the relationship between the two branches in git status and git branch -v.

How do I Grep a specific branch in Git?

Using Git grep command for local branches examples For searching any committed tree, working directory etc. you may use the grep command of Git. The grep command is a big topic, however, in our context of showing branches, the command below shows how you may use it: $ git branch -a | grep -v ‘remotes’


1 Answers

Quoting from that same manual page you linked:

If --list is given, or if there are no non-option arguments, existing branches are listed; the current branch will be highlighted with an asterisk. Option -r causes the remote-tracking branches to be listed, and option -a shows both local and remote branches. If a <pattern> is given, it is used as a shell wildcard to restrict the output to matching branches. If multiple patterns are given, a branch is shown if it matches any of the patterns. Note that when providing a <pattern>, you must use --list; otherwise the command is interpreted as branch creation.

So the answer, at least according to the documentation, is that "it is used as a shell wildcard". This assumes, of course, that you know what the phrase "shell wildcard" means—and more importantly, it's wrong, since a straight shell wildcard would not match across the /.

The documentation should say something like: "The pattern acts much like a shell wildcard / glob pattern, except that slashes are not treated specially, so that a*b matches both accb and ac/cb, and a[bc/]* matches all of a/d, abcd, ac/cb, and accb."

Examples:

$ git branch -a   a/d   abcd   ac/cb   accb * master $ git branch --list 'a*b'   ac/cb   accb $ git branch --list 'a[bc/]*'   a/d   abcd   ac/cb   accb $  
like image 131
torek Avatar answered Oct 08 '22 14:10

torek