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
🌐
Git
git-scm.com › docs › git-pull
Git - git-pull Documentation
By default, git checks if a branch ... to skip this check for performance reasons. If used during git-pull the --ff-only option will still check for forced updates before attempting a fast-forward update....
🌐
GeeksforGeeks
geeksforgeeks.org › git › git-pull-force
Git Pull Force - GeeksforGeeks
August 26, 2024 - If there are conflicts between your local changes and the fetched changes, Git prompts you to resolve them manually. A “force pull” refers to forcefully updating your local branch with the remote branch, disregarding any local changes.
Discussions

How to force update when doing git pull? - Stack Overflow
I'm doing git pull of an open source lib, I don't care what my local copy is I just want to update it with the origin's version. i.e. it can blow away my local changes. More on stackoverflow.com
🌐 stackoverflow.com
version control - How do I force "git pull" to overwrite local files? - Stack Overflow
Then I am able to pull just fine. ... Thanks! I found that this is needed if you've made any special adjustments to ignore changes on file in the repo. i.e git update-index --assume-unchanged 2023-01-20T23:25:40.777Z+00:00 ... Save this answer. ... Show activity on this post. ... $ git branch -m [branch_to_force... More on stackoverflow.com
🌐 stackoverflow.com
git - How can I pull updates from a force-pushed branch? - Stack Overflow
I aim to minimise commits on each merge request. To achieve this I rebase locally before pushing to the MR and, if required, rebase against "old" MR commits and force-push the result. (I More on stackoverflow.com
🌐 stackoverflow.com
How to Perform a Git Force Pull?
If you just don't give a damn about the changes you've made and just want to pull down what's in your remote (assuming the same branch) you can do the following: git reset --hard && git pull The first command resets the working directory and staging area to the last commit you have for your branch. Then you just pull like normal. If you've made commits that aren't in remote and you want to get rid of those as well, you can do the following, assuming your remote's name is origin git fetch --all && git reset origin/ More on reddit.com
🌐 r/learnprogramming
3
2
December 7, 2020
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
🌐
Codecademy
codecademy.com › article › force-git-pull
How to Force Git Pull to Overwrite Local Changes in Git | Codecademy
Merge: It merges those fetched changes into our current branch. If there are no conflicts between our local changes and the remote changes, git pull is straightforward and doesn’t require any special actions. Let’s say we’re working on a project and want to update our local branch from the remote branch.
🌐
Squash
squash.io › how-to-update-branches-in-git-using-git-force-pull-and-git-pull
How to Update Branches in Git using Git Force Pull and Git Pull
Here is an example of how to use the git pull --force command: ... Again, replace branch_name with the name of the remote branch that you want to update your local branch with.
Top answer
1 of 3
99

This should do the trick:

git reset --hard HEAD
git pull
2 of 3
42
git fetch
git checkout origin/name_of_branch  # correct state but in 'head without a name'
git checkout -B name_of_branch      # overwrite current tree onto name_of_branch

This checks out the remote tracking branch into a head without a name, then you can have a look and check you're happy. Whenever you want to (even after changes or commits) the second git checkout labels your current tree with 'name_of_branch', even if it has to delete the old name_of_branch to do so.


Edit: 'What a crazy command line syntax'

The syntax of git commands seems unintuitive. In fact it's the Git data model that is unintuitive. This isn't bad design, but because it works with files, branches, commits in ways that are much more flexible and powerful than other version control systems. Once you grok how these things work in Git, the command line will make a lot of sense and you will be able to accurately guess how to do complicated things.

  • git fetch This fetches all the updates that have happened on the origin server since the last time. Git separates fetching from the server from updating, merging, etc. any of your branches. All the branches called origin/XXX are your most recent versions of what's on the server. They are not remote branches but remote tracking branches, local branches which track remote branches. When you do git fetch, you update them, without touching any of your own branches. When you do git merge, git rebase, and so on, you use the fetched version, without grabbing a more recent copy from the server. This means you have control over when network requests are made (if you aren't always connected to the server), and you can 'fetch' a snapshot of the server, then merge at your leisure. If in doubt, do git fetch first.
  • git checkout origin/name_of_branch git checkout does two things. It updates your files to that branch, and it sets your HEAD to that branch. The files things is what you'd expect. The HEAD things means that when you do commits, they will added to the end of the branch that HEAD points to. IOW, checkout does both output - write the right versions of the files, and prepares for input - gets ready to store the commits you are going to do in the right place. If you checkout a branch called foo, your tree changes to the state saved in foo, and the next commits you do will be added to foo. In the case of origin\xyz, you can't write your changes to an origin branch - these track what is on the origin server and can't be committed to directly. So the checkout updates the files, and sets HEAD to nothing - an unnamed branch. This stops you accidentally committing your newly checked out stuff back onto the previous branch you were using, and in fact you will be heavily discouraged by git from committing at all until you have a destination branch.
  • git checkout -B name_of_branch As usual, when git does two different things with one command, both of them can be configured separately. So the second part of what checkout does, setting HEAD to the branch you want to commit to, can be to a new branch, instead of the branch you're checking out, if you use the -B option. So git checkout -B new_stuff old_stuff will set all your files to the state in old_stuff, but get you ready to write your commits to the new branch new_stuff. This is a common task, and saves you checking out a branch then forking it, in two steps. Now, almost all arguments to git commands can be omitted, and git will do the most obvious thing. In this case, that is making a new branch based on the one you are on, rather than one you want to checkout. So git takes the unnamed branch you are on, and makes a new branch called name_of_branch, which you can start committing to. Note that an uppper case letter "B" kind of means 'force'. If you used "-b" git would refuse to overwrite an already existing branch. With "-B" it will go ahead and do it without warning or confirming.
Find elsewhere
🌐
DataCamp
datacamp.com › tutorial › git-pull-force
Git Pull Force: How to Overwrite a Local Branch With Remote | DataCamp
August 6, 2024 - However, this command cannot be used to override our local changes because git pull will try to merge our local version with the remote. Under the hood, git pull performs the following steps: It uses git fetch to download the latest version of the remote repository.
🌐
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.
🌐
Scaler
scaler.com › home › topics › git › git pull force
Git Pull Force - Scaler Topics
May 4, 2023 - The command used to pull the changes from a new branch of a remote repo in Git is: The Git pull force technique allows you to update your local repository with the latest changes of the remote repo even if you have some leftover uncommitted commits local. This force-pulling concept is different ...
🌐
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 - Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force) allows overwriting local branches. It is always used with source and destination branches mentioned as parameters.
🌐
FlatCoding
flatcoding.com › home › git pull force: safely overwrite local changes
Git Pull Force: Safely Overwrite Local Changes - FlatCoding
March 30, 2025 - A less dirty way of forcing a pull in Git uses git fetch in conjunction with git reset. This updates your local repository to reflect the one from remote and discards changes that aren’t committed as of yet.
🌐
GitProtect.io
gitprotect.io › strona główna › how to use git pull force to overwrite local files
How to Use Git Pull Force to Overwrite Local Files - Blog | GitProtect.io
September 17, 2024 - Git doesn’t have a direct ‘git pull –force’ command, but you can achieve a similar effect by using ‘git fetch’ followed by ‘git reset –hard origin/main’ to overwrite a local branch.
🌐
Reddit
reddit.com › r/learnprogramming › how to perform a git force pull?
r/learnprogramming on Reddit: How to Perform a Git Force Pull?
December 7, 2020 - First, run a fetch to update all origin/<branch> refs to latest: git fetch --all · Backup your current branch: git checkout -b backup-master · Then, you have two options: git reset --hard origin/master · OR If you are on some other branch: ...
🌐
Git
git-scm.com › docs › git-fetch › 2.28.0
Git - git-fetch Documentation
By default, git checks if a branch is force-updated during fetch. Pass --no-show-forced-updates or set fetch.showForcedUpdates to false to skip this check for performance reasons. If used during git-pull the --ff-only option will still check for forced updates before attempting a fast-forward ...
🌐
LoginRadius
loginradius.com › home
How to Perform a Git Force Pull
February 24, 2026 - it feels like it would help to overwrite local changes. instead, it fetches forcefully but does not merge forcefully (git pull --force = git fetch --force + git merge). Like git push, git fetch allows us to specify which local and remote branch ...
🌐
GoLinuxCloud
golinuxcloud.com › home › devops › git › git pull force explained: safely overwrite local changes (step-by-step)
Git Pull Force Explained: Safely Overwrite Local Changes (Step-by-Step) | GoLinuxCloud
March 22, 2026 - When someone force pushes to a remote branch, the commit history is rewritten. This causes your local branch to go out of sync, and a normal git pull may fail because Git cannot merge incompatible histories using git merge. To fix this and align your local branch with the updated remote:
🌐
ITsyndicate
itsyndicate.org › blog › how-to-use-git-force-pull-properly
Git Pull Force to Overwrite Local Changes - Right Way
The following method is the most effective way to force git pull: ... (If you are working with branches, use the branch name instead of master branch).