Branching and Merging
What a branch actually is
A branch is simply a movable pointer to a specific commit — creating one is instant and cheap, which is exactly why Git-based workflows encourage creating a new branch for every feature or fix, rather than working directly on the main line of history.
git branch feature-login # create a new branchngit checkout feature-login # switch to itngit checkout -b feature-signup # create AND switch in one step
Working on a branch
Once you have switched to a branch, every commit you make adds to that branch specifically — your main branch (commonly called main) stays exactly as it was, completely unaffected, until you deliberately bring the changes back together.
Merging
git checkout mainngit merge feature-login
This brings the commits from feature-login into main. If the two branches changed different, unrelated parts of the codebase, Git merges them automatically with no input needed from you — conflicts only arise when both branches changed the exact same lines, covered in a later lesson.
Deleting a merged branch
git branch -d feature-login
Once a branch’s work has been merged, it has served its purpose — deleting it (Git will refuse if it detects unmerged work, as a safety check) keeps your branch list from accumulating clutter over a project’s lifetime.
A typical everyday workflow
git checkout -b fix-typon# ... make your changes ...ngit add .ngit commit -m "Fix typo in course description"ngit checkout mainngit merge fix-typongit branch -d fix-typo
This create-branch → commit → merge → delete cycle is the core rhythm of working with Git, repeated dozens or hundreds of times over the life of a real project.