The Team Contract: When Not to Rebase
This is about discipline, not commands. A real, written policy, landed the normal way.
Every rebase technique this block has covered — squash, split, reorder, reword — genuinely rewrites history. That is completely safe on a real branch nobody else has seen. It is a real, genuine hazard the instant anyone else has pulled it.\n\nThis lesson is not about a new command — it is about real, professional judgment. git log <branch> --not --remotes reveals exactly which real commits on a branch exist ONLY locally, never yet shared. Combined with git branch -vv, this becomes a genuine, reliable way to answer "is this actually safe to rebase?" before ever running the command.
Real Diagnostics, Not Guesswork
git branch -vv
git log feature/recipe-search --not --remotes --oneline
A branch with real commits shown here has never been pushed — genuinely safe to rebase. A branch with an [origin/...] tracking marker already has a real, shared copy elsewhere.
Master Is Never Safe
git log master --not --remotes --oneline
Empty output on master means exactly what it should: every real commit here is already shared. Master is never a real candidate for rebasing.
Writing the Real Policy
git switch -c docs/rebasing-policy
# write REBASING.md
git commit -m "Document the team's rebasing policy"
git push -u origin docs/rebasing-policy
A real, permanent, committed document — not a Slack message that gets lost, not a rule everyone half-remembers differently.
git log <branch> --not --remotes
Lists exactly the real commits on a branch that exist ONLY locally — nowhere on any remote. Confirmed directly in this lab: empty output on master proved every real commit there is already shared; real output on a feature branch proved it never has been.
A written team policy as a real, committed document
A rule that only lives in memory or chat history is not really a team policy — confirmed directly in this lab by writing it into the actual repository as REBASING.md, reviewed and merged exactly like any other real change.
🔍 Diagnose Which Real Branches Are Safe
Real commands, not guesswork — which branches have never been shared?
cd ~/team-recipes && git switch mastercd ~/team-recipes && git branch -vvcd ~/team-recipes && git log feature/recipe-search --not --remotes --onelinecd ~/team-recipes && git log master --not --remotes --onelinestudent@lab:~$ cd ~/team-recipes && git switch master Switched to branch 'master' Your branch is up to date with 'origin/master'. student@lab:~$ cd ~/team-recipes && git branch -vv feature/dinner-plans af4b942 [origin/feature/dinner-plans] Add Wednesday soup night feature/meal-recipes f8550bd Add dessert recipe feature/prices aa2cc0c [origin/feature/prices] Add spice rack price guide feature/recipe-search 26aa08c Add recipe search feature * master b495745 [origin/master] Merge pull request: pancake toppings student@lab:~$ cd ~/team-recipes && git log feature/recipe-search --not --remotes --oneline 26aa08c (feature/recipe-search) Add recipe search feature student@lab:~$ cd ~/team-recipes && git log master --not --remotes --oneline
📜 Write the Real Team Policy
A genuine, permanent document — not a rule everyone half-remembers differently.
cd ~/team-recipes && git switch -c docs/rebasing-policycd ~/team-recipes && printf 'Rebasing Policy\n\nSafe to rebase: a solo branch nobody else has fetched or pushed to.\nNever rebase: master, or any branch someone else may already have pulled.\nAsk first: a branch with an open PR someone is actively reviewing - rebasing it rewrites the commits they are looking at.\n' > REBASING.mdcd ~/team-recipes && git add REBASING.mdcd ~/team-recipes && git commit -m "Document the team's rebasing policy"cd ~/team-recipes && git push -u origin docs/rebasing-policystudent@lab:~$ cd ~/team-recipes && git switch -c docs/rebasing-policy Switched to a new branch 'docs/rebasing-policy' student@lab:~$ cd ~/team-recipes && printf 'Rebasing Policy\n\nSafe to rebase: a solo branch nobody else has fetched or pushed to.\nNever rebase: master, or any branch someone else may already have pulled.\nAsk first: a branch with an open PR someone is actively reviewing - rebasing it rewrites the commits they are looking at.\n' > REBASING.md student@lab:~$ cd ~/team-recipes && git add REBASING.md student@lab:~$ cd ~/team-recipes && git commit -m "Document the team's rebasing policy" [docs/rebasing-policy 2ae3fd7] Document the team's rebasing policy 1 file changed, 5 insertions(+) create mode 100644 REBASING.md student@lab:~$ cd ~/team-recipes && git push -u origin docs/rebasing-policy Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 466 bytes | 58.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git * [new branch] docs/rebasing-policy -> docs/rebasing-policy branch 'docs/rebasing-policy' set up to track 'origin/docs/rebasing-policy'.
🔗 Land It the Normal Way
Even a policy document goes through the same real, reviewed process.
cd ~/team-recipes && git switch mastercd ~/team-recipes && git merge --no-ff docs/rebasing-policy -m 'Merge pull request: rebasing policy'cd ~/team-recipes && git pushcd ~/team-recipes && git branch -d docs/rebasing-policycd ~/team-recipes && git push origin --delete docs/rebasing-policystudent@lab:~$ cd ~/team-recipes && git switch master Switched to branch 'master' Your branch is up to date with 'origin/master'. student@lab:~$ cd ~/team-recipes && git merge --no-ff docs/rebasing-policy -m 'Merge pull request: rebasing policy' Merge made by the 'ort' strategy. REBASING.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 REBASING.md student@lab:~$ cd ~/team-recipes && git push Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 230 bytes | 76.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git b495745..70d76d9 master -> master student@lab:~$ cd ~/team-recipes && git branch -d docs/rebasing-policy Deleted branch docs/rebasing-policy (was 2ae3fd7). student@lab:~$ cd ~/team-recipes && git push origin --delete docs/rebasing-policy To ../recipes-origin.git - [deleted] docs/rebasing-policy
Lab 3.1.4 complete. Real diagnostics, and a real, permanent team policy:\n\n\n Real branches diagnosed : ✅ git log --not --remotes\n Policy written down : ✅ REBASING.md\n Landed the normal way : ✅ reviewed, merged\n
Enable JavaScript to run the live terminal and track your progress.