Work isolation

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.

Select a branch to see how internal Git pointers update:
File on disk: .git/HEAD ref: refs/heads/main Active branch pointer: .git/refs/heads/... 3a8f91c78490a1b2c3d4e5f6a7b8c9d0e1f2a3b4
C1
C2
C3
HEAD β†’ main
Integration strategies

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.

Current mode: Fast-Forward (linear history, zero extra commits).
Case 1: Fast-Forward (main did not move)
main:
C1
C2 (base)
C3 (login)
C4 (login)
═════► main se desliza a C4

βœ“ No extra commits. History remains completely linear and clean.

Conflict anatomy

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.

1. Common ancestor (C2)
// config.ts
export const discount = 0.10;
export const currency = 'USD';

Original value agreed last week.

2. Rama main (HEAD)
// config.ts
export const discount = 0.15;
export const currency = 'USD';

Marketing raised discount to 15% in main.

3. Rama feature
// 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.

Interactive resolution

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:

Quick resolution options:
src/config.ts ⚠️ CONFLICT
// 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.

Terminal and commands

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.

1
git status

Verify conflicting files listed as "both modified".

2
Editar y validar

Open file, delete markers, pick final code, and run tests.

3
git add src/config.ts

Marks conflict resolved and moves clean file into Staging Area.

4
git commit

Generates merge commit. In modern Git: git merge --continue.

πŸ›Ÿ Emergency escape hatch: git merge --abort

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.

Best practices

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.

01

Short-lived branches

A branch alive for 2 days rarely conflicts. A branch open for 3 weeks accumulates hundreds of changes.

02

Modularity and small files

If 5 developers edit a 3000-line God File, they will clash daily. Split into cohesive, single-responsibility modules.

03

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.

04

Communicate before massive refactors

If you are reformatting or renaming key directories, notify the team and merge during a coordinated window.