Intermediate · 10 min · practise every command in the built-in terminal

Branches

A branch is an independent line of development — great for working on a feature without touching the stable code.

Create and switch branches

git branch feature-login          # Create
git switch feature-login          # Switch (modern)
git checkout feature-login        # Switch (classic)
git switch -c feature-login       # Create + switch in one step

List branches

git branch            # Local branches
git branch -a         # All, including remote

Merge a branch into the current one

git switch main
git merge feature-login

Merge conflicts

When two branches change the same lines, Git can't decide automatically:

<<<<<<< HEAD
your version
=======
incoming version
>>>>>>> feature-login

Edit the file to keep what you want, remove the markers, then:

git add file.txt
git commit

Delete a branch

git branch -d feature-login       # Safe delete (merged only)
git branch -D feature-login       # Force delete

Practice tasks

  1. Create and switch to a new branch called 'feature-login'
  2. List all local branches
  3. Delete the feature-login branch
  4. List all branches, including remote-tracking ones

Commands in this lesson

Git & Version Control