⚠ 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
If there’s a merge conflict during the merge or rebase that you don’t want to handle, you can safely abort it with git merge --abort or git rebase --abort. ... The "remote" repository to pull from.
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 ...
🌐
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 ...
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Rebasing
Git - Rebasing
Next, the person who pushed the ... push --force to overwrite the history on the server. You then fetch from that server, bringing down the new commits. Figure 46. Someone pushes rebased commits, abandoning commits you’ve based your work on · Now you’re both in a pickle. If you do a git pull, you’ll ...
🌐
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 - Git Rebase (and related: pull, merge, force-push) Overview This guide explains how git pull, git merge, and git rebase work, how commit history is structured, and when you need to use …
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 history, they will be listed as commits that will ...
🌐
FlatCoding
flatcoding.com › home › git pull force: safely overwrite local changes
Git Pull Force: Safely Overwrite Local Changes - FlatCoding
March 30, 2025 - Then, after pulling the latest code, you can reapply those saved changes. If there are no conflicts, everything will merge smoothly. If there are conflicts, Git will let you know which files need fixing. There’s also another way using --rebase. Let’s move on to the next section to learn it. While Git has no --force ...
🌐
Graphite
graphite.com › guides › git-rebase-force
Force pushing after a Git rebase - Graphite
Additionally, when a pull request that's part of a stack is merged, Graphite detects the change and automatically rebases the remaining branches in the stack onto the updated base. This prevents issues like incorrect diffs or mis-assigned reviewers in your pull requests. Git force push after ...
🌐
Flexiple
flexiple.com › git › git-pull-force
Git Pull Force – How to Overwrite Local Changes With Git - Flexiple
After fetching the latest changes with git fetch, use git merge origin/<branch_name> to merge them into your branch, addressing any merge conflicts that surface. Each method serves specific scenarios: Stash for temporary context switches, Rebase for a cleaner project history, and Merge for collaborative work, ensuring a coherent and conflict-free codebase without resorting to force pulls...
🌐
Continuously Merging
articles.mergify.com › git-pull-rebase
A Developer’s Guide to Git Pull Rebase
November 9, 2025 - Pull requests started failing, and nobody could cleanly push their work. Getting things back on track was a painful, multi-step process: First, we had to tell everyone to stop working immediately. 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...
🌐
Stevenharman
stevenharman.net › git-pull-with-automatic-rebase
Git Pull with Automatic Rebase | Steven Harman — Maker & Breaker of Things
June 9, 2011 - Rather than git pull I use git pull --rebase. The --rebase option will fetch the remote commits and rebase your commits on top of the new commits from the remote. This is the “re-writing” of history folks often talk about. You can tell git to use rebase, rather than merge, in one of two ways, depending on your situation. # Force ...
🌐
Understandable
understandable.dev › deep-dives › git-rebase-vs-git-merge-never-force-push-again
Git Rebase vs Git Merge: Never Force Push Again | Understandable
Doing a force push after or while getting code reviewed causes pain for both you and your reviewer. Avoid force pushes by using git merge instead of git rebase. ... Here’s a scenario: You’ve made a feature branch. You worked on some code. Now you put it up for a pull request on GitHub.
🌐
Atlassian
atlassian.com › git › tutorials › merging vs rebasing
Merging vs. Rebasing | Atlassian Git Tutorial
December 16, 2025 - Note that this rebase doesn’t violate the Golden Rule of Rebasing because only your local feature commits are being moved—everything before that is untouched. This is like saying, “add my changes to what John has already done.” In most circumstances, this is more intuitive than synchronizing with the remote branch via a merge commit. By default, the git pull command performs a merge, but you can force ...
🌐
OpenMSCG
software.rcc.uchicago.edu › help
Introduction to Git rebase, force-push, and merge conflicts
CAUTION: Warning: git rebase rewrites the commit history. It can be harmful to do it in shared branches. It can cause complex and hard to resolve merge conflicts. In these cases, instead of rebasing your branch against the default branch, consider pulling it instead (git pull origin master).
🌐
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 - If there are commits on the remote ... after a force push. After this post was published, Steve Gordon tweeted with a thing he’d like to add to this. Since I think it was a good addition, I’ve added the tweet for you below. Great post on Git rebasing! One thing I'd add is that this is fairly safe on a personal GitHub fork and/or where you're reasonably confident no one else has pulled the remote ...
🌐
Gitready
gitready.com › home › advanced › pull with rebase
Pull with rebase
May 28, 2024 - Git users are likely familiar with the git pull command, which fetches data from a specified remote repository and merges it with the current branch. However, there’s an alternative approach: pulling changes with rebase. This can often result in a cleaner, more linear history.
🌐
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...