1. Branching and Merging Commands
git branchWhat it doesDisplays a list of local branches with the active branch marked with a star
When to use itto see which branches are available and determine where you currently stand
Example
git branchgit branch -aWhat it doesDisplays all local and remote branches (Remote Tracking Branches)
When to use itto check branches uploaded to GitHub
Example
git branch -agit branch <name>What it doesCreates a new branch without moving to it
When to use itto prepare a branch for an upcoming task
Example
git branch feature/authgit switch <branch>What it doesMoves to a pre-existing branch
When to use itto switch between different tasks
Example
git switch maingit switch -c <name>What it doesCreates a new branch and jumps to it immediately in one step
When to use itto start a new feature or hotfix
Example
git switch -c fix/login-validationgit merge <branch>What it doesMerge the selected branch into the currently active branch
When to use itto merge changes after the feature is finished and tested
Example
git merge feature/authgit merge --abortWhat it doesCancels the ongoing merge and returns the branch to its state before the merge started
When to use itWhen complex conflicts arise and you want to start over safely
Example
git merge --abortgit branch -d <name>What it doesDeletes a local branch safely when it has already been merged
When to use itto clean up branches after merging them into main
Example
git branch -d feature/authgit branch -D <name>What it doesForce delete a local branch even if it is not merged (Force Delete)
When to use itTo remove an obsolete test branch that you no longer need
Example
git branch -D experiment/failed-test