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.

Answer from AD7six on Stack Overflow
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
🌐
SciVision
scivision.dev › git-pull-after-force-push
git pull after remote forced update | Scientific Computing
May 31, 2022 - When collaborating in teams with Git, someone else may do a “force push” on a feature branch, that conflicts with local revisions previously pulled. Here are a few simple scenarios to resolve this situation quickly. For simplicity, in this article we assume work in a Git branch feat1. First, make a copy of the Git repo in case a mistake is made. Erase local changes in feat1 and match the remote Git repo. ... The work can be committed as usual after the reset.
Discussions

Am I using git push --force the right way?
That sounds like the right approach, and the one I use. After the rebase, your local dev1 history is different than the remote's dev1 branch. That is expected after a rebase, because a rebase changes history. Though I would recommend that you use --force-with-lease instead of --force to avoid clobbering any commits that you do not have locally which might have been pushed to the dev1 branch. Just a good habit. More on reddit.com
🌐 r/git
9
7
October 4, 2018
How to pull after a forced git push? - Stack Overflow
Suppose I pull changes from a git repo. Then the author of the repo force pushes to the central repo. Now I can't pull since the history is rewritten. How can I pull the new commits (and abandon t... More on stackoverflow.com
🌐 stackoverflow.com
Can you do pull (or equivalent) from a branch when history is rewritten without merge?
When the branch is updated by someone else and push to GitHub… You do this git fetch origin git reset --hard origin/ Fyi if you made any changes to the branch they will be lost. More on reddit.com
🌐 r/git
15
2
June 23, 2025
Git - After Rebase, recommend Push (Force)
There's a Git (Extension) pop-up that detects attempts to pull after "rebase onto", but it doesn't say why pull might be a bad idea nor does it offer the correct action Push (Force). More on github.com
🌐 github.com
4
September 14, 2023
🌐
GitHub
gist.github.com › hugoduraes › ed79ac69866682867d74ecc62ba4cdbb
git-pull-after-forced-push.md · GitHub
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 ...
🌐
DataCamp
datacamp.com › tutorial › git-pull-force
Git Pull Force: How to Overwrite a Local Branch With Remote | DataCamp
August 6, 2024 - Learn why git pull --force isn’t the best way to overwrite a local branch with the remote version, and discover the proper method using git fetch and git reset.
🌐
freeCodeCamp
freecodecamp.org › news › git-pull-force-how-to-overwrite-local-changes-with-git
Git Pull Force – How to Overwrite Local Changes With Git
July 20, 2020 - After that, you can run git dc whenever you wish to review the changes. Going this way, we can set up a few aliases related to the previous use cases. [alias] pull_force = !"git fetch --all; git reset --hard HEAD; git merge @{u}" pf = pull_force pull_stash = !"git fetch --all; git stash; git merge @{u}; git stash pop"
🌐
Codecademy
codecademy.com › article › force-git-pull
How to Force Git Pull to Overwrite Local Changes in Git | Codecademy
Learn how to force `git pull` in Git to overwrite local changes safely using `git reset --hard` and `git stash`. Understand use cases, risks, and best practices.
🌐
Quora
quora.com › How-do-I-force-git-pull-to-overwrite-local-files-1
How to force 'git pull' to overwrite local files - Quora
Answer (1 of 17): You can probably do [code]git stash git stash drop # deletes the latest changes on the stash [/code]However [code ]git reset HEAD —hard[/code] would be the proper way to do what you want. This resets your git workspace to the latest commit on the local branch, and discards ...
Find elsewhere
🌐
Reddit
reddit.com › r/git › am i using git push --force the right way?
r/git on Reddit: Am I using git push --force the right way?
October 4, 2018 -

Hello everyone,

I would like to know if I'm using git push --force the right way. Here is my scenario:

  1. I branched off master (let's call my branch dev1) which I did some work on and then pushed up remotely

  2. A ton of work has been done on `master` I've been working on dev1 locally

  3. I want my local dev1 branch to have all the updated changes that master has so I rebased

  4. At this point, my local dev1 is way out of sync with remote dev1. Git is saying if I want to sync them up then I need to do a git pull (but I definitely don't want to pull the changes down from the remote branch to my newer, local branch).

Assuming no one else works on dev1, am I supposed to git push --force to sync local `dev1` to remote `dev1`? If not, what are my alternatives?

🌐
Git Tower
git-tower.com › blog › force push in git - everything you need to know
Force Push in Git - Everything You Need to Know | Tower Blog
August 18, 2021 - You could use Interactive Rebase to remove that commit from your project, and then you would have to Force Push it to the remote repository to make sure that it is deleted for everyone else when your colleagues update the local version via git pull.
🌐
Medium
medium.com › @granthgharewal › why-git-asks-you-to-pull-after-a-rebase-and-how-to-fix-it-2f6fd55106c0
Why Git Asks You to Pull After a Rebase (and How to Fix It) | by Granth Gharewal | Medium
August 29, 2025 - Git blocks a normal push and asks you to pull, but pulling reintroduces the old commits. The correct fix is to force push with lease after rebasing.
🌐
Codemia
codemia.io › knowledge-hub › path › git_pull_after_forced_update
Git pull after forced update
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
Top answer
1 of 4
141

Throwing away your local changes

If you want to discard your work, fetch and reset. For example, if you have a remote named origin and a branch named master:

$ git fetch origin
$ git reset --hard origin/master # Destroys your work

Keeping your local changes

If you don't want to throw away your work, you will have to do a git rebase --onto. Suppose the old origin looks like this:

A ---> B ---> C
              ^
              origin/master

And you have this:

A ---> B ---> C ---> X ---> Y ---> Z
              ^                    ^
              |                    master
              origin/master

Now, the upstream changes change things:

A ---> B ---> C ---> X ---> Y ---> Z
 \                                 ^
  ---> B'---> C'                   master
              ^          
              origin/master

You would have to run git rebase --onto origin/master <C> master, where <C> is the SHA-1 of the old origin/master branch before upstream changes. This gives you this:

A ---> B ---> C ---> X ---> Y ---> Z
 \
  ---> B'---> C'---> X'---> Y'---> Z'
              ^                    ^
              |                    master
              origin/master

Notice how B, C, X, Y, and Z are now "unreachable". They will eventually be removed from your repository by Git. In the meantime (90 days), Git will keep a copy in the reflog in case it turns out you made a mistake.

Fixing mistakes

If you git reset or git rebase wrong and accidentally lose some local changes, you can find the changes in the reflog.

In the comments, a user is suggesting git reflog expire with --expire=now but DO NOT RUN THIS COMMAND because this will DESTROY your safety net. The whole purpose of having a reflog is so that Git will sometimes save your neck when you run the wrong command.

Basically, what this command will do is immediately destroy the B, C, X, Y, and Z commits in the examples above so you can't get them back. There's no real benefit to running this command, except it might save a little bit of disk space, but Git will already purge the data after 90 days so this benefit is short-lived.

2 of 4
2

If you do not have local commits, this will recover your checkout from a force push. You will be up to date with the remote branch, and able commit your local work after that.

git fetch
git stash
git reset --hard origin/master # destroys your work
git stash pop # restores your work as local changes
git mergetool # fix any conflicts

At this point you have your local changes as they were before. Your checkout is up to date with all the changes on master, or whatever branch you are working from.

🌐
Reddit
reddit.com › r/git › can you do pull (or equivalent) from a branch when history is rewritten without merge?
r/git on Reddit: Can you do pull (or equivalent) from a branch when history is rewritten without merge?
June 23, 2025 -

I have this situation.

Somoene create a branch that I checkout locally (or create PR and use use github command to checkout the PR).

The author of the branch modify the history (do a rebase or squash).

The branch can only be midified bu the author (a social rule), so I want to fetch the new changes and have the same history as the author.

Is there something like git pull --force? Or is the delete a branch and checkout it again the only option?

What is the simplest way to achieve something like this?

🌐
Graphite
graphite.com › guides › git-pull-overwrite-local-changes
How to overwrite local changes when executing a git pull command
After popping the stash, you may need to resolve conflicts between your local changes and the newly pulled changes. The standard git pull command acts only on the currently checked-out branch, fetching and integrating remote changes specifically into that branch.
🌐
Atlassian
atlassian.com › git › tutorials › syncing › git pull
How to Pull a Git Repository? | Atlassian Git Tutorial
Assume that we are at a starting point of our first diagram, and we have executed git pull --rebase. In this diagram, we can now see that a rebase pull does not create the new H commit. Instead, the rebase has copied the remote commits A--B--C and rewritten the local commits E--F--G to appear after them them in the local origin/main commit history.
🌐
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 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.
🌐
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.
🌐
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)
January 7, 2020 - 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. Imagine you want to add commits to the main branch. Since you opened the PR, new commits were added to the main branch. When you do a Git rebase you take that latest state of the main branch. Then commit by commit your changes are re-added on top of the latest state on main. After each commit is replayed there is a check if there are conflicts which you should then fix, but more on that later.
🌐
Maecapozzi
maecapozzi.com › blog › recover-after-force-push
How to Recover an Overwritten Commit After a --force-push<!-- --> | The Garden
Have you ever accidentally overwritten a colleague's work with a force push? Here's an easy way to recover without anyone ever having to know.
🌐
GitHub
github.com › microsoft › vscode › issues › 193143
Git - After Rebase, recommend Push (Force) · Issue #193143 · microsoft/vscode
September 14, 2023 - (Does this mean that VS Code skips the pull, but tries the push as part of the Sync after all... even though we clicked Don't Pull?) The only correct action after an intentional and successful "rebase onto" is a Push (Force).
Author   microsoft