⚠ Warning:

Any uncommitted local change to tracked files will be lost, even if staged.

But any local file that's not tracked by Git will not be affected.


First, update all origin/<branch> refs to latest:

git fetch --all

Backup your current branch (e.g. main):

git branch backup-main

Jump to the latest commit on origin/main and checkout those files:

git reset --hard origin/main

Explanation:

git fetch downloads the latest from remote without trying to merge or rebase anything.

git reset resets the master branch to what you just fetched. The --hard option changes all the files in your working tree to match the files in origin/main.


Maintain current local commits

[*]: It's worth noting that it is possible to maintain current local commits by creating a branch from main before resetting:

git checkout main
git branch new-branch-to-save-current-commits
git fetch --all
git reset --hard origin/main

After this, all of the old commits will be kept in new-branch-to-save-current-commits.

Uncommitted changes

Uncommitted changes, even if staged (with git add), will be lost. Make sure to stash or commit anything you need. For example, run the following:

git stash

And later (after git reset), reapply these uncommitted changes:

git stash pop

Which may create merge conflicts.

Answer from RNA on Stack Overflow
🌐
Git
git-scm.com › docs › git-pull
Git - git-pull Documentation
You can also set the configuration options pull.rebase, pull.squash, or pull.ff with your preferred behaviour.
Discussions

Git pull after forced update - Stack Overflow
I just squashed some commits with git rebase and did a git push --force (which is evil, I know). Now the other software engineers have a different history and when they do a git pull, Git will mer... More on stackoverflow.com
🌐 stackoverflow.com
How can I make a clean pull request using git rebase?
If you are seeing commits from the main branch in your PR, that means you are not up-to-date. You can ensure you are rebasing on top of the latest main branch with: git pull --rebase origin main Tip: you can make rebasing the default too. So you'd just need to do git pull origin main And then your branch would be rebased on top of the latest main. See https://github.com/yawaramin/dotfiles/blob/d7df7b17053ccd8ce0297238e546deddf1a6446b/gitconfig#L42 More on reddit.com
🌐 r/git
7
2
December 7, 2024
Magit: How do you do "git pull --no-rebase"?
No rebase is the default for both magit and git More on reddit.com
🌐 r/emacs
14
8
October 23, 2023
Do you use both pull.ff and pull.rebase?
so how about an explanation on the what and why? More on reddit.com
🌐 r/git
22
8
July 17, 2021
🌐
GitLab
docs.gitlab.com › topics › git › git_rebase
Rebase and resolve merge conflicts | GitLab Docs
Pulling has similar effects with less risk of compromising others’ work. When you use Git to rebase, each commit is applied to your branch. When merge conflicts occur, you are prompted to address them. For more advanced options for your commits, use an interactive rebase. ... You must have permissions to force push to branches.
🌐
Coderwall
coderwall.com › p › 7aymfa › please-oh-please-use-git-pull-rebase
Please, oh please, use git pull --rebase (Example)
March 8, 2024 - ALWAYS rebase origin/shared-branch versus just shared-branch, so you rebase against the shared branch and can ignore your local version if you have one. You probably need to "share it" for a pull request; no problem, but you'll need force push to update it, and again, nobody else should push to that.
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Rebasing
Git - Rebasing
Rebase on top of force-pushed rebase work · This only works if C4 and C4' that your partner made are almost exactly the same patch. Otherwise the rebase won’t be able to tell that it’s a duplicate and will add another C4-like patch (which will probably fail to apply cleanly, since the changes would already be at least somewhat there). You can also simplify this by running a git pull --rebase instead of a normal git pull.
🌐
Medium
medium.com › @natsuko-dev-blog › git-rebase-and-related-pull-merge-force-push-34bb748f0115
Git Rebase (and related: pull, merge, force-push) | by Natsuko | Medium
April 22, 2026 - A merge commit is created when histories diverge and you run git merge. ... Want a clean, linear history (your own branch)? → Use rebase → If already pushed, use --force-with-lease
Top answer
1 of 5
794

To receive the new commits

git fetch

Reset

You can reset the commit for a local branch using git reset.

To change the commit of a local branch:

git reset origin/main --hard

Be careful though, as the documentation puts it:

Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.

If you want to actually keep whatever changes you've got locally - do a --soft reset instead. Which will update the commit history for the branch, but not change any files in the working directory (and you can then commit them).

Rebase

You can replay your local commits on top of any other commit/branch using git rebase:

git rebase -i origin/main

This will invoke rebase in interactive mode where you can choose how to apply each individual commit that isn't in the history you are rebasing on top of.

If the commits you removed (with git push -f) have already been pulled into the local history, they will be listed as commits that will be reapplied - they would need to be deleted as part of the rebase or they will simply be re-included into the history for the branch - and reappear in the remote history on the next push.

Use the help git command --help for more details and examples on any of the above (or other) commands.

2 of 5
128

Pull with rebase

A regular pull is fetch + merge, but what you want is fetch + rebase. This is an option with the pull command:

git pull --rebase

In your particular case, commits have been removed which you don't want to be reapplied. This has to be done manually. Therefore, the rebase needs to be interactive so these commits can be skipped:

git pull --rebase=interactive

or as of Git 2.26 can be shortened to:

git pull --rebase=i
Find elsewhere
🌐
GitHub
gist.github.com › hugoduraes › ed79ac69866682867d74ecc62ba4cdbb
git-pull-after-forced-push.md · GitHub
This will invoke rebase in interactive mode where you can choose how to apply each individual commit that isn't in the history you are rebasing on top of. If the commits you removed (with git push -f) have already been pulled into the local ...
🌐
FlatCoding
flatcoding.com › home › git pull force: safely overwrite local changes
Git Pull Force: Safely Overwrite Local Changes - FlatCoding
March 30, 2025 - Let’s move on to the next section to learn it. While Git has no --force option for pull, doing a git pull --rebase will give you a similar result, reapplying your local changes on top of the latest updates from the remote.
🌐
Graphite
graphite.com › guides › git-rebase-force
Force pushing after a Git rebase - Graphite
This command is necessary because the history of your local branch has diverged from the remote branch. In order to complete the rebase, you must rewrite the history of the remote repository using git push --force.
🌐
Flexiple
flexiple.com › git › git-pull-force
Git Pull Force – How to Overwrite Local Changes With Git - Flexiple
Use this when you're not ready to commit local changes but need to pull the latest updates. git stash followed by git pull and then git stash pop reintegrates your work safely. Git Rebase rewrites the commit history by integrating changes from ...
🌐
Stevenharman
stevenharman.net › git-pull-with-automatic-rebase
Git Pull with Automatic Rebase | Steven Harman — Maker & Breaker of Things
June 9, 2011 - # Force existing branches to use rebase. $ git config branch.*branch-name*.rebase true
🌐
Continuously Merging
articles.mergify.com › git-pull-rebase
A Developer’s Guide to Git Pull Rebase
November 9, 2025 - We then used git reflog on the remote server's repository to find the commit hash from before the disastrous rebase. A senior developer had to force-push the old, correct history back to the develop branch using git push --force.
🌐
Gerald Versluis Blog
blog.verslu.is › gerald versluis — . net maui, git hub copilot & ai powered development › blog posts — . net maui, git hub copilot & ai development › git › git rebase don't be afraid of the force ( push)
Git Rebase: Don't be Afraid of the Force (Push) - Gerald Versluis
January 7, 2020 - As you can see, there are a lot of reasons for a rebase. This is where things start to get a bit scary, because it involves rewriting history due to force pushing. Let me expand on that. What will happen during a Git rebase is that the commits you want to add to the codebase are replayed on top of the target branch.
🌐
Understandable
understandable.dev › deep-dives › git-rebase-vs-git-merge-never-force-push-again
Git Rebase vs Git Merge: Never Force Push Again | Understandable
Now you should be able to push without a force push! # get up to date git fetch # reset to the origin git reset origin/feature # revert all the commits we don't want git revert --no-commit C..Y git commit -m "Reverting back to B" # add our new commit git cherry-pick Z · If there’s no (or minimal) conflicts between Z and all of C..Y, you could avoid the git reset and git cherry-pick and do git pull --rebase instead, which will rebase just Z on top of your feature branch (same as the git cherry-pick does), and then do the git revert --no-commit C..Y after that.
🌐
DEV Community
dev.to › ruqaiya_beguwala › day-1330-git-pull-rebase-keep-your-history-linear-when-pulling-changes-4poe
Day 13/30 - Git Pull --rebase: Keep Your History Linear When Pulling Changes - DEV Community
June 3, 2025 - While git pull --rebase is great for keeping a linear history, it can be even more powerful when used in advanced workflows. Here are some scenarios where it shines beyond basic branch synchronization. If you enforce a linear history policy on your main branch (common in CI/CD workflows), using --rebase ensures no merge commits sneak in. ... Resolve any conflicts. Push your changes (may require --force-with-lease if already pushed).
🌐
OpenMSCG
software.rcc.uchicago.edu › help
Introduction to Git rebase, force-push, and merge conflicts
If you haven't pushed your commits to the remote branch before rebasing, push your changes normally. If you had pushed these commits already, force-push instead. Note that the steps for editing through the command line can be slightly different depending on your operating system and the shell you're using. See Numerous undo possibilities in Git for a deeper look into interactive rebase.
🌐
Atlassian
atlassian.com › git › tutorials › merging vs rebasing
Merging vs. Rebasing | Atlassian Git Tutorial
December 16, 2025 - This is like saying, “add my ... a merge, but you can force it to integrate the remote branch with a rebase by passing it the --rebase option....
🌐
Gitready
gitready.com › home › advanced › pull with rebase
Pull with rebase
May 28, 2024 - You can achieve this by adding the --rebase option to your pull command: ... But why is this beneficial? Sometimes, instead of merging in the upstream changes, it’s cleaner to reapply your work on top of them.