From a feature branch, apply only the latest commit on top of the latest main
branch β and discard all earlier commits in that branch.
- Your feature branch is named:
my-feature
- You want to keep only the most recent commit from
my-feature
- You want it based on the latest
origin/main
# 1. Check out your feature branch
git checkout my-feature
# 2. Reset the branch to match origin/main, but keep the latest commit's changes
git reset --soft origin/main
# 3. Re-commit the top commit changes on top of main
git commit -m "Your top commit message"
# (Optional) Verify the history
git log --oneline --graph --decorate