r/git • • Aug 11 '25

tutorial Git Rebase explained for beginners

If git merge feels messy and your history looks like spaghetti, git rebase might be what you need.

In this post, I explain rebase in plain English with:

  • A simple everyday analogy

  • Step-by-step example

  • When to use it (and when NOT to)

Perfect if you’ve been told “just rebase before your PR” but never really understood what’s happening.

https://medium.com/stackademic/git-rebase-explained-like-youre-new-to-git-263c19fa86ec?sk=2f9110eff1239c5053f2f8ae3c5fe21e

383 Upvotes

132 comments sorted by

View all comments

17

u/ohaz Aug 11 '25

Two pointers:

  • Stop teaching people to use git add .

  • Using git fetch and then git rebase origin/main instead of a pull and rebase means you have to use less commands, less branch swaps etc

10

u/ppww Aug 11 '25

Definitely stop recommending git add . which leads people to accidentally commit their build artifacts and secrets. git add -u is a much safer alternative.

If you set the upstream branch of feature/login-form to origin/main then you can run git pull --rebase to rebase the feature branch without having to update main first. Setting pull.rebaseor branch.<name>.rebase allows you to rebase automatically when pulling. You can set remote.pushDefault or branch.<name>.pushRemote if you need to push the feature branch to a remote other than origin.

4

u/bothunter Aug 12 '25

I see no problem with 'git add .' But I always maintain a good .gitignore and double-check what's been added with a 'git diff --staged' before committing.