Git Topics (9)Tap to view
    Git·Version Control·Topic 4 of 9

    Git Branching & Merging

    Managing local and remote branches, moving between them, merging, and canceling ongoing mergers.

    1. Branching and Merging Commands

    1. git branch

      What 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

      Examplegit branch

    2. git branch -a

      What it doesDisplays all local and remote branches (Remote Tracking Branches)

      When to use itto check branches uploaded to GitHub

      Examplegit branch -a

    3. git branch <name>

      What it doesCreates a new branch without moving to it

      When to use itto prepare a branch for an upcoming task

      Examplegit branch feature/auth

    4. git switch <branch>

      What it doesMoves to a pre-existing branch

      When to use itto switch between different tasks

      Examplegit switch main

    5. git 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

      Examplegit switch -c fix/login-validation

    6. git 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

      Examplegit merge feature/auth

    7. git merge --abort

      What 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

      Examplegit merge --abort

    8. git 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

      Examplegit branch -d feature/auth

    9. git 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

      Examplegit branch -D experiment/failed-test

    Offline · Reading cached copy