Skip to content

Instantly share code, notes, and snippets.

@thomaskanzig
Created April 29, 2025 16:46
Show Gist options
  • Save thomaskanzig/ee8dff635322b2e42e378d8d41adc157 to your computer and use it in GitHub Desktop.
Save thomaskanzig/ee8dff635322b2e42e378d8d41adc157 to your computer and use it in GitHub Desktop.
How to use git rebase

How to use git rebase

To update your current branch (fix/STORY-1343-hero-section) from the main branch using rebase instead of merge, follow these steps:

# First, fetch the latest changes from remote
git fetch origin

# Then rebase your current branch on top of main
git rebase origin/main

# Then update your code to the repository:
git push --force-with-lease origin HEAD

If you encounter any conflicts during rebase:

  1. Resolve the conflicts manually
  2. Add the resolved files with git add <file>
  3. Continue the rebase with git rebase --continue

Using rebase instead of merge keeps your commit history linear and cleaner, making it appear as if you built your changes directly on top of the latest main branch.

The --force-with-lease flag is safer than just --force as it will fail if someone else has made changes to the remote branch that you haven't fetched yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment