← Lesson
BitWithBite
Git & GitHub · Quick Reference

Lesson 4 — Branches & Merging Cheat Sheet

Git & GitHub
In one line: A branch is a parallel timeline of your project. The default branch is called main (or master in older repos). When you create a new branch, you get an independent copy of the h...

Key Ideas

1What is a Branch?. A branch is a parallel timeline of your project. The default branch is called main (or master in older repos). When you create a new branch, you get an independent cop...
2Branch Commands. You only need a handful of commands to work with branches effectively. Here are all the essential ones:
3Merging Branches. When your feature is complete and tested, you merge it back into main. Git performs the merge automatically in most cases.
4Merge Conflicts: What They Are & How to Resolve Them. A merge conflict happens when both branches modified the same lines of the same file. Git can't decide which version to keep — it asks you to decide manually.
5git stash — Save Work in Progress. Sometimes you're in the middle of work but need to switch branches urgently (to fix a bug, help a colleague). git stash temporarily shelves your changes without commit...

Code Examples

# List all local branches (* = current branch) git branch # List all branches including remote git branch -a # Create a new branch git branch feat/user-auth # Switch to a branch (modern syntax) git switch feat/user-auth # Old syntax (still works) git ch...
# 1. Switch to the branch you want to merge INTO git switch main # 2. Merge the feature branch into main git merge feat/user-auth # 3. Delete the feature branch (optional, keeps things clean) git branch -d feat/user-auth
# Git puts conflict markers in the file: <<<<<<< HEAD const greeting = "Hello"; # Your version (main) ======= const greeting = "Hi there"; # Their version (feature branch) >>>>>>> feat/update-greeting # TO RESOL...