⚠ 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
🌐
Reddit
reddit.com › r/git › how to overwrite local changes from remote repository?
r/git on Reddit: How to overwrite local changes from remote repository?
March 11, 2022 -

Basically I want to clone a repository, regardless of whether that repository exists locally or not. If there is a local version I want it overwritten. I don't to synchronise any local changes to the master repo, I want a one directional flow of information from the remote repository to the local one. Seems like it should be straightforward, but I can't find an easy way to do this. My solution is to delete the folder and re-clone it every time I want to update it, but that seems wrong. Is there a command for this? something like git clone -force repositorylink

🌐
Git Tower
git-tower.com › learn › git faq › how do i force git pull to overwrite local files?
How do I force git pull to overwrite local files? | Learn Version Control with Git
5 days ago - Force a git pull to overwrite local files: Stash or discard changes & untracked files, then pull. Avoid conflicts with Tower's auto-stashing!
🌐
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 - When such an operation modifies ... git push --force allows overwriting remote branches, git fetch --force (or git pull --force) allows overwriting local branches....
🌐
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 ...
🌐
Brian Childress
brianchildress.co › git-force-overwrite-of-local-file-with-remote
GIT: Force Overwrite of Local File with Remote File - Brian Childress
#GIT, reset · Sometimes we just need to reset a local file with what is saved in a remote repository. For example, you’re working locally and your files just get into a place where you need to reset, maybe only a file or two. Maybe you’ve merged in another branch and there are numerous conflicts and you just want whatever the remote branch has, whatever the reason, here are a few commands you can use. Overwriting a single file ·
Find elsewhere
🌐
Graphite
graphite.com › guides › git-pull-overwrite-local-changes
How to overwrite local changes when executing a git pull command
The behavior of git pull regarding ... By default, git pull does not overwrite unstaged local changes unless there is a conflict between your local changes and the changes coming from the remote repository....
🌐
Lineserve
lineserve.net › home › blog › how to force git pull to overwrite local files: complete step-by-step guide
How to Force Git Pull to Overwrite Local Files: Complete Step-by-Step Guide — Lineserve Blog
December 11, 2025 - Force a Git pull to overwrite local files using git fetch with git reset –hard, or preserve work with git stash, avoiding untracked-file merge errors.
🌐
whatapalaver
whatapalaver.co.uk › git-patching-with-diff
Git Diff and Patch | whatapalaver
December 1, 2020 - If you need to resolve a git merging/rebasing nightmare you could choose to create a diff file and then apply this as a patch to a clean branch. First you need to ensure you have committed the changes in your working branch that you wish to keep. Then checkout master and pull any remote changes to ensure your local version of master is up to date.
🌐
Adamdurrant
adamdurrant.co.uk › blog › undo-git-commit
How to Undo Pushed Git Commits Locally & Remotely<!-- --> | ADurrant
Run git add . and then git rebase --continue after each conflict resolved. In my example case, I had two merge conflicts (as my commits were all changes to the same file). After resolving those we need to push the rebase to the remote repo.
🌐
Roger Perkin
rogerperkin.co.uk › home › git tutorials › git commands
Git Commands Cheat Sheet with Examples » Git Tutorial
December 28, 2022 - Git checkout is also used to revert changes. You can “checkout” the last version of a file to overwrite your local file to the last committed version.
🌐
Cusf
wiki.cusf.co.uk › Git_and_GitHub
Git and GitHub - CUSF Wiki
Note that you can use git status to see what changes have been added ... Sometimes you realise you need to change something right after commiting. For this, the following command is useful. It will overwrite the previous commit instead of making a new one. ... Note that you should only do this before pushing, or conflicts will occur. In order to sync your local changes with the remote (e.g.
🌐
PracticalSeries
practicalseries.com › 1002-vcs › 02-02-concept.html
Version control with Git | PracticalSeries: Brackets-Git and GitHub
Once we add a file to the staging area, Git begins to track it, in Git parlance; it is now a file to be commited. If we continued to modify the file in the working area, nothing would happen to the staged (files in the staging area are said to be staged) version of the file. If we wanted to overwrite the file in the staging area with a modified working copy, we would need to add it again.
🌐
Unity
discussions.unity.com › news & general discussion
GIT with Visual Studio - Can't pull, please help - News & General Discussion - Unity Discussions
November 10, 2021 - I have some basic version control set up using Visual Studio so that I can work on my game on two different computers. It has been working; I have been able to make commits and then push and pull them to copy over the c…
🌐
Fjolt
fjolt.com › article › git-what-changed
Using Git to see recent changes in specified a time period
August 29, 2022 - It is recommended to use git log instead, as it’s still possible to show all files using this command too, by typing git log --since='2 weeks ago' --stat
🌐
DefProc
defproc.co.uk › home › git workflow for self-updating sites
Git Workflow for Self-Updating Sites | DefProc
February 25, 2020 - Basically I’m using one bare repository as the master copy (hub repository) and automatically pull from and push to the live website folder (prime repository), while allowing remote access with manual push/pulls to make offline code adjustments (in working clones) that are pushed to the live directory automatically. All the while using git to flag up the commit problems for manual merging, so the live site never gets borked by a outdated overwrite.
🌐
Noreiko
noreiko.com › blog › unnatural-file-changes-git
Unnatural file changes with git | Joachim's blog
This is what we want, but it has one crucial flaw. Suppose patch 1 added a new file, foo.php. When we check out master's files, foo.php is not changed, because it's not on master. There's nothing on master to overwrite it. The git checkout master -- .