Git & GitHub
/Beginner
What is a Branch?
Definition
A branch represents an independent line of development. Branches serve as an abstraction for the edit/stage/commit process.
Explain Like I'm New
Imagine a tree trunk (the `main` codebase). You want to build an experimental new 'Dark Mode' feature, but you don't want to break the trunk if you make a mistake. You grow a 'branch' off the trunk. You can do whatever you want on that branch in an alternate universe. When the feature is perfect, you merge the branch back into the trunk.
Real World Example
In a company, 50 developers can work on 50 different features on the same day by creating 50 separate branches. They don't step on each other's toes.
Common Use Cases
- •Developing features in isolation
- •Fixing bugs safely
- •Experimentation
Terminal Output
bash / terminal
// Conceptual Mental Model
/*
(Feature Branch)
/--- Commit D --- Commit E
/
Commit A --- Commit B --- Commit C
(main branch)
Commit E has access to everything in A and B.
But Commit C does NOT have the experimental code from D or E!
*/
Interview Questions
basic
- What is the default name of the primary branch in Git?
intermediate
- Are branches in Git 'heavy' (meaning they duplicate all the files on your hard drive)?