← Back to Blog

Team Git Policy: Short, Practical, and Safe

Team Git Policy (Short & Practical)

Goal: Keep collaboration safe, history honest, and day-to-day work stress-free.

This policy optimizes for teams, not individual preferences or fancy commit graphs.

1. Never Rebase Shared Branches

Once a branch is pushed and someone else might pull it:

❌ Do NOT

git rebase main
git push --force
✔ DO

git merge main

Why: Rebase rewrites history. Rewritten history breaks teammates’ local branches and trust in the repository.

2. Rebase Is Allowed Only on Local, Unshared Work

Rebase is allowed only if all of these are true:

  • The branch is local
  • It has not been pushed
  • No one else depends on it
# Local cleanup before first push
git rebase -i main

The moment you push the branch → stop rebasing.

3. Prefer Merge Commits During Development

git merge main

Merge commits:

  • Preserve how work actually happened
  • Show when integration occurred
  • Are safe for team collaboration

A slightly messy history is better than a broken one.

4. Squash Only at the Boundary (PR → main)

If you want a clean main branch:

✔ Use Squash and Merge in GitHub / GitLab
❌ Don’t squash or rebase while a PR is still active

Why this works:

  • Review context stays intact
  • Developers keep simple workflows
  • main stays readable without harming collaboration

5. Never Force Push to Shared Branches

❌ Do Not git push --force
✔ git push

Exception: Very rare recovery situations, explicitly agreed upon and communicated to the whole team.

6. One Branch = One Purpose

✔ Good examples:

  • feature/user-search
  • fix/payment-timeout

❌ Avoid:

  • Long-lived branches
  • Mixing unrelated changes in one branch

Smaller branches are easier and safer to merge.

7. Optimize for Team Safety, Not Clean Graphs

Remember:

  • Git is a collaboration tool
  • History is a debugging tool
  • Clean graphs are optional
  • Broken trust is expensive

8. If You’re Unsure — Don’t Rewrite History

When in doubt:

git merge
  • You can always understand merge history.
  • You can’t easily recover rewritten history.

In Short,

Don’t rewrite history once others depend on it. Merge freely. Squash at the boundary. Keep it boring.