A branch is not a folder copy: it is a 41-byte movable pointer
Creating a branch in Git does not copy your project files on disk. A branch is simply a 41-byte text file in .git/refs/heads/ containing a commit SHA. HEAD is a symbolic pointer indicating where you stand.
ref: refs/heads/main Active branch pointer: .git/refs/heads/... 3a8f91c78490a1b2c3d4e5f6a7b8c9d0e1f2a3b4 Fast-Forward vs 3-Way Merge: when is a merge commit born?
If main has not advanced while you worked on feature, Git does a Fast-Forward (simply sliding the main pointer). If main also moved forward, histories diverged and Git performs a 3-Way Merge creating a union commit with two parents.
β No extra commits. History remains completely linear and clean.
βΉ Git compares common ancestor (C2) with C3 and C4. Commit M has two parents: C3 and C4.
Why does a conflict happen? The machine cannot guess intent
Git automatically merges changes across different files or separated lines. But when two developers modify the exact same lines of the same file, Git has no business criteria to know which is correct.
// config.ts
export const discount = 0.10;
export const currency = 'USD'; Original value agreed last week.
// config.ts
export const discount = 0.15;
export const currency = 'USD'; Marketing raised discount to 15% in main.
// config.ts
export const discount = 0.20;
export const currency = 'USD'; Black Friday task set 20% in feature.
β οΈ 15% or 20%? No algorithm can make this decision for you. Git pauses the merge and hands you control.
Deconstructing conflict markers in your editor
When a conflict occurs, Git edits your file inserting 3 delimiters: <<<<<<< HEAD (current version), ======= (separator), and >>>>>>> (incoming version). Resolve the conflict below:
// src/config.ts
<<<<<<< HEAD
export const discount = 0.15; // VersiΓ³n en main
=======
export const discount = 0.20; // VersiΓ³n en feature
>>>>>>> feature/login
export const currency = 'USD'; File has active conflict markers. Click one of the 3 options to clean it up.
git add to mark resolved, git commit to seal
Once the file is cleaned and markers are deleted, you must inform Git. The git add command tells Git the file is resolved in Staging, and git commit seals the final merge commit.
Verify conflicting files listed as "both modified".
Open file, delete markers, pick final code, and run tests.
Marks conflict resolved and moves clean file into Staging Area.
Generates merge commit. In modern Git: git merge --continue.
If you made a mistake, the conflict is unmanageable, or you need to consult a peer, run git merge --abort. Git safely cancels the merge and restores your repository to the exact pre-merge state.
Fewer conflicts is not luck: it is architectural discipline
Conflicts are not avoided by luck, but by designing code and workflow to minimize concurrent collision zones between developers.
Short-lived branches
A branch alive for 2 days rarely conflicts. A branch open for 3 weeks accumulates hundreds of changes.
Modularity and small files
If 5 developers edit a 3000-line God File, they will clash daily. Split into cohesive, single-responsibility modules.
Regularly sync with main
Bring main changes into your branch multiple times a day. Solving a 2-line conflict today beats 40 files on Friday.
Communicate before massive refactors
If you are reformatting or renaming key directories, notify the team and merge during a coordinated window.