0
0
Gitdevops~5 mins

Listing branches in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Listing branches
Start in Git repo
Run 'git branch'
Git reads local branches
Display list of branches
End
The flow shows how Git lists all local branches when you run the 'git branch' command.
Execution Sample
Git
git branch
This command lists all local branches in the current Git repository.
Process Table
StepActionEvaluationResult
1Run 'git branch' commandGit checks local branch referencesFinds branches: main, feature1, bugfix
2Prepare output listMark current branch with '*'* main feature1 bugfix
3Display branches to userOutput list shown in terminalBranches listed with current branch marked
4EndNo more actionsCommand completes
💡 All local branches listed and command finishes
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
branchesempty[main, feature1, bugfix][* main, feature1, bugfix][* main, feature1, bugfix][* main, feature1, bugfix]
current_branchunknownmainmainmainmain
Key Moments - 2 Insights
Why is one branch marked with an asterisk (*)?
The asterisk (*) marks the current branch you are on, as shown in execution_table step 2 where '* main' indicates 'main' is active.
Does 'git branch' show remote branches?
'git branch' by default shows only local branches. To see remote branches, you need 'git branch -r'. This is why only local branches appear in the output in execution_table step 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the list of branches after step 1?
A[* main, feature1, bugfix]
B[main]
C[main, feature1, bugfix]
Dempty
💡 Hint
Check the 'branches' variable in variable_tracker after Step 1
At which step is the current branch marked with '*'?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Look at the 'Action' and 'Result' columns in execution_table for marking
If you want to list remote branches, what should you do?
ARun 'git branch'
BRun 'git branch -r'
CRun 'git branch -a'
DRun 'git remote show'
💡 Hint
Recall key_moments about local vs remote branches
Concept Snapshot
git branch
Lists all local branches in the current repository.
The current branch is marked with '*'.
To list remote branches, use 'git branch -r'.
To list all branches (local + remote), use 'git branch -a'.
Full Transcript
When you run 'git branch', Git reads all local branch references in your repository. It then prepares a list of these branches and marks the current active branch with an asterisk (*). Finally, it displays this list in your terminal. This command only shows local branches. To see remote branches, you need to add the '-r' option. The current branch marking helps you know which branch you are working on. The command finishes after displaying the list.