Force overwrite of local file with what's in origin repo?

Viewed 346910

I want to get the latest file that's in the repository, and overwrite what I have locally. How can I do this with the git client?

7 Answers

This worked for me:

git reset HEAD <filename>

I believe what you are looking for is "git restore".

The easiest way is to remove the file locally, and then execute the git restore command for that file:

$ rm file.txt
$ git restore file.txt 

if you want to override all your local changes with specific branch then u can do

git reset --hard origin/feature/branchname

feature/branchname -> is my branch name by which I replaced my all local changes

My intention to take all the changes from feature/branchname branch and commit to a branch in which I am working, the name of my branch is 'mybranch'. Then I first replaced my local changes which is I already pushed to my branch mybranch, then I have to pushed this command to my branch. Force push command is

git push --force

It will push whatever changes I got from 'feature/branchname' branch to my 'mybranch'.

After running into this problem, I finally tried git checkout --force <branch> and it did exactly that.

Related