Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between git branch and git branch -l

Tags:

git

In Windows operating system, I clone a git warehouse with Git Bash. I use Git Bash to manipulate git branch and git branch -l, and find that they all list local branch names. When I manipulate git branch -h, it lists that -l, --list list branch names, but it doesn't mention that -l list local branches. I'm confused whether their functions are same

like image 671
Kartone Avatar asked Mar 02 '26 18:03

Kartone


2 Answers

Sometimes a table can make it easier to see.

git branch Shows local Shows remote
x
-l or --list x
-r or --remote x
-a or --all x x

So --list is the default you get if you only type git branch.

DESCRIPTION

If --list is given, or if there are no non-option arguments, existing branches are listed; the current branch will be highlighted in green and marked with an asterisk. Any branches checked out in linked worktrees will be highlighted in cyan and marked with a plus sign. Option -r causes the remote-tracking branches to be listed, and option -a shows both local and remote branches.

git-scm.com - git-branch

like image 67
candied_orange Avatar answered Mar 05 '26 06:03

candied_orange


The git branch command is used to list, create, or delete branches. By default, it lists the names of all local branches in the repository. For example, running git branch without any additional options will display a list of all local branches:

$ git branch
  Yourbranch1
  Yourbranch2

The -l option is used to limit the list of branches to those that match a specified pattern. For example, running git branch -l "feat*" will list all branches that start with the prefix "feat"

$ git branch -l "feat*"
  feat/feature1
  feat/feature2
like image 29
iShox Avatar answered Mar 05 '26 07:03

iShox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!