Git Branch

Leaving the master notebook untouched while freely writing on a separate copy made at that exact moment.

Definition In Git, a version control tool for code, a branch is an independent line of work split off from the main timeline. It inherits all previous history up to that point, letting you add new changes without touching the original code—so if things go wrong, you can easily go back.

Drafting on a Copy While Keeping the Original Safe

Imagine making a class magazine with your classmates. Everyone is writing in a single notebook. Now, suppose you want to try out a brand-new story idea.

Writing directly in the original notebook is risky. If you don't like how it turns out, erasing and rewriting leaves a mess that can ruin earlier pages. Instead, you photocopy everything written so far into a fresh notebook and draft your idea there freely.

In Git, this working copy is called a branch. When created, it contains the exact same content as the original, but any new work you write after that stays only on this copy. The original notebook remains untouched.

Even the original timeline is just another branch. It is usually called the `main` branch, and everyone treats it as the finished, official edition.

Feature branch branching from main and merging back Copy here Feature branch Main branch Join

Working Together and Merging When Ready

You don't make the magazine alone. Multiple classmates take their own copies to write different sections. Whatever someone else writes, your own copy stays completely unaffected.

Once someone finishes their section, they paste those pages back into the master notebook. In Git, combining work from a branch back into the main line is called merging. From that point on, their work becomes part of everyone's official version.

Trouble arises when two people edit the exact same page in different ways. If one expanded a sentence while the other deleted it, a person must manually decide which version to keep. This dilemma is called a conflict.

That is why holding onto a branch for too long makes merging painful; the original changes too much in the meantime. It is much easier to keep branches small and merge often.

A Closer Look Under the Hood

Git doesn't actually copy the entire notebook file by file. A branch is essentially a simple movable label that points to the latest page of a timeline. As you add a new page, the label simply moves along to that page.

That is why creating a branch takes virtually no time or disk space. It is as simple as sticking on a new label. Developers often create and delete several branches in a single day.

There is another closely related term: a commit. A commit is an individual saved snapshot—like a single saved page in the notebook. A branch is the named timeline formed by those connected pages.

So, you don't need to think of a branch as an entirely separate universe. It's just a way to bookmark your spot on the main road and step aside to experiment freely without worry.

🤔 Common misconceptions

✕ Myth

Creating a branch copies the entire project folder, taking up a lot of extra disk space.

✓ Fact

A branch is just a lightweight pointer to the latest commit. Because Git does not duplicate all project files, creating or deleting branches is virtually instantaneous and costs almost no storage.

✕ Myth

Making changes in a branch automatically updates the code in the main branch.

✓ Fact

Changes made after branching exist only within that isolated branch. To apply them to the main line, you must explicitly perform a merge.

🧺 Where you meet it

1 Adding a new checkout screen to a shopping app: developers build it in an isolated branch while the live production code remains stable.
2 Fixing a sudden bug report: creating a quick hotfix branch to repair the issue, then merging it back into the main branch.
💡 In one sentence

A branch is an isolated workspace split off from previous history, letting you experiment with new code without risking the original project.