Git Workflow

1. GitHub Merge Strategies

FeatureMerge CommitRebaseSquash Merge
History StyleBranched and verbosePerfectly linearClean and linear
Commit TypeKeeps all commits, adds a new merge commitRewrites original commits,
Moves commits to the tip of the base branch.
Condenses / folds all commits to one commit
TraceabilityHigh (exact history)Low (original context lost)Low (individual steps lost)
SafetyHigh (non-destructive)Do not use on public brach, its intended to be used on private branches onlySafe for final integration
Best ForPublic/shared branches,
Audit trails and complex feature integration where history matters.
Local/private cleanup,
Maintaining a purely linear history without merge noise.
Finalising feature PR,
Keeping the main branch clean and concise.

What is the difference between merge commit and squash merge?

Summary of Differences

FeatureMerge CommitSquash Merge
History StyleVerbose and branched1Clean and linear5
Commit CountKeeps all original commits + 1 merge commit1Reduces all commits to exactly one4
TraceabilityHigh; sees every incremental change2Low; sees only the final result8
WorkflowStandard non-destructive integration1Used for cleaning up “messy” histories

2. Git Rebase Essentials

  • Definition: Re-applying commits on top of another base tip.

  • When to use: To keep your local feature branch up to date with master without adding unnecessary merge commits.

  • When to avoid: Never rebase branches that others are working on. Rewriting history causes git push --force requirements which can delete teammates’ work.

Git Rebase

Applies the commits of the current branch ahead of a specified branch to create a linear history?

The Golden Rule of Rebasing

You should **never use it on public branches

The most critical distinction is when to use each tool. The Golden Rule of Rebasing states that you should never use it on public branches.

  • Why: Because rebasing creates new commits, if you rebase a shared branch like main, your local history will diverge from everyone else’s. To fix this, teams must merge the diverged branches back together, leading to a confusing mess of duplicate commits.
  • Safe Usage: Rebasing is intended for private feature branches to clean up local history before a final merge. If a branch is public and being looked at by others, you must use git merge to incorporate changes.

Summary Comparison

Featuregit mergegit rebase
History StyleBranched and verboseClean and linear
Commit TypeCreates a new merge commitRewrites original commits
SafetyHigh (non-destructive)Risky if used on public branches
TraceabilityHigh (exact history preserved)Low (original context is lost)
Best ForPublic/shared branchesPrivate/local branch cleanup
https://www.atlassian.com/git/tutorials/merging-vs-rebasing