Scenario
You were working on the dev branch.
While you were making commits locally, someone (or you) also made changes directly to the main branch on GitHub.
As a result, both branches moved forward independently.
What Happened?
Initial State
A (common commit)
β
βββ main
βββ dev
Both branches point to the same commit.
Changes Added to Main
A ββ B ββ C (main)
β
ββββββββββββ (dev)
Example:
- B = README update
- C = CodeQL update
Changes Added to Dev
A ββ B ββ C (main)
β
βββ D ββ E ββ F (dev)
Example:
- D = Base crawler
- E = Class-based crawler
- F = Concurrency implementation
Now both branches contain unique commits.
This situation is called:
Branches have diverged.
Why git pull main Did Not Work
Many developers think:
git pull main
means:
"Pull changes from main branch"
But Git interprets it differently.
main is only a local branch name.
Git expects:
git pull <remote> <branch>
Example:
git pull origin main
Where:
-
origin= GitHub repository -
main= branch on GitHub
Correct Way to Update Dev
While on the dev branch:
git fetch origin
git merge origin/main
What Does git fetch Do?
git fetch origin
Downloads the latest information from GitHub.
Before fetch:
Local Git:
main -> C
GitHub:
main -> G
After fetch:
main -> C
origin/main -> G
Git now knows about the latest remote commits.
No files are changed yet.
What Does git merge origin/main Do?
git merge origin/main
Git combines:
dev
+
latest main
Before merge:
A ββ B ββ C (origin/main)
β
βββ D ββ E ββ F (dev)
After merge:
A ββ B ββ C
β \
β M (dev)
β /
βββ D ββ E ββ F
M = Merge Commit
Now dev contains:
- All main changes
- All dev changes
If Merge Conflicts Occur
Git may stop and show:
CONFLICT
Example:
Both branches modified:
README.md
Git cannot decide which version to keep.
You must manually fix the file.
After fixing:
git add .
git commit
Git creates the merge commit.
Push Updated Dev
git push origin dev
Now GitHub receives the merged version.
main -> C
dev -> M
Create Pull Request
dev ---> main
GitHub PR contains:
- README updates
- CodeQL updates
- Crawler changes
- Concurrency changes
Everything together.
Alternative Workflow
You may also update your local main first.
git checkout main
git pull origin main
git checkout dev
git merge main
git push origin dev
Result:
latest main
+
latest dev
=
updated dev
Simple Mental Model
Think of branches as two roads.
main road
B ββ C
/
A
\
D ββ E ββ F
dev road
Both roads started from the same place.
Before creating a Pull Request, connect the roads:
B ββ C
/ \
A M
\ /
D ββ E ββ F
Now everything is connected.
Safe Workflow Summary
git checkout dev
git fetch origin
git merge origin/main
# fix conflicts if needed
git add .
git commit
git push origin dev
Create PR:
dev β main
This is the safest and most common workflow when main and dev have diverged.













