3

I have organized my branches into folders and subfolders. I am only accessing my GIT repo through the CLI. I would like to be able to list only branches inside a branch folder.

FEATURE/branch-1
FEATURE/branch-2
FEATURE/CURRENT/branch-000
FEATURE/CURRENT/branch-001
FEATURE/CURRENT/branch-002
* master
dev
v2.0.0/branch-3
v2.1.0/branch-4
v2.1.0/branch-5

> git branch shows me everything, however I would like to only see the v2.1.0 folder. Is there a command that can output only the v2.1.0 branch folder from my example above?

Also, as a bonus, is there a way to get a branch subfolder FEATURE/CURRENT/**?

Greg K.
  • 1,005
  • 2
  • 12
  • 20
  • 1
    Side note to *all* the answers below: if you're using a Unix style shell, you may need to quote the asterisk in some circumstances, e.g., `git branch --list 'v2.1.0/*'`. This occurs when there's also a *file* that matches the pattern: the shell will expand the `*` before Git ever has a chance to use it for branch names. – torek Mar 29 '19 at 18:52

3 Answers3

3

git branch --list *v2.1.0* will show all branches with v2.1.0 in their branch name

EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28
  • This answer is nice. I like the simplicity of the output and I may add that I can reduce this by one more character `git branch --list v2.1.0*` – Greg K. Mar 29 '19 at 18:52
  • Now that I played with this and accepted the answer, I'd like to now see if there's a **not** command. so look for all ** v2.1.0* ** but not *TEST* – Greg K. Mar 29 '19 at 19:30
  • 1
    You could pipe it into grep. Not sure how to do NOT within the git branch command. `git branch --list v2.1.0* | grep -iv test` The 'v' negates the grep and the 'i' makes it case insensitive. – EncryptedWatermelon Apr 01 '19 at 12:21
1

Probably git show branch is what you're looking for. You can use globs and everything.

For instance, if you've got master, b/one and b/two

git show-branch b/*

will show

! [b/one] Some changes
 ! [b/two] changed to kk2
--
 + [b/two] changed to kk2
++ [b/one] Some changes

There's a bit of stuff (like the last commit) besides the branch name, but that will only list the branches you are looking for.

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
  • Great link, but this shows me an exhaustive list of commits whereas I'm trying to quickly see what branches are inside one branch folder. git show branch shows commits, which I am not looking for. – Greg K. Mar 29 '19 at 18:41
  • If I can see an example what would look like. I also do not need to see what is in the remote repository. – Greg K. Mar 29 '19 at 18:43
  • 1
    `git branch --list *OBE*` will show all branches with OBE in their branch name – EncryptedWatermelon Mar 29 '19 at 18:44
1

Try this one:

git branch -a --list v2.1.0/*

I think it will solve your problem