Chapter

Rewriting history

Reshape your commits before sharing them: rebase vs merge, interactive rebase, cherry-pick, tags and releases, and the golden rule of when not to rewrite.

Git Basics 5 Lessons from courses

About this chapter

In this chapter you'll learn how to reshape your history instead of just adding to it. You'll see the real difference between merge and rebase, clean up a messy branch with interactive rebase before opening a pull request, copy a single commit with cherry-pick, and mark releases with tags. Most importantly, you'll learn the one rule that keeps rewriting safe: never rewrite commits other people have already pulled.

Lessons from courses

  1. 1 Rebase vs merge Git rebase vs merge, explained with diagrams: merge keeps history and adds a merge commit, rebase replays commits for a linear history. When to use each.
  2. 2 Interactive rebase Clean up a branch before a pull request with git interactive rebase: squash commits, reword, reorder, edit and drop, step by step for beginners.
  3. 3 Cherry-picking commits Git cherry-pick copies one specific commit onto your current branch by its hash. When to use it, how to handle a cherry-pick conflict, and common mistakes.
  4. 4 Tags and releases Mark releases with git tag: lightweight vs annotated tags, pushing tags with git push --tags, and a quick note on semantic versioning like v1.2.0.
  5. 5 When not to rewrite history The golden rule of Git: never rewrite commits others have pulled. Force-push dangers explained, plus why --force-with-lease is safer than --force.
Git Basics Go to course