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

0 votes
asked Oct 16, 2010 by blankman

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?

3 Answers

0 votes
answered Oct 16, 2010 by amber

If you want to overwrite only one file:

git fetch
git checkout origin/master <filepath>

If you want to overwrite all changed files:

git fetch
git reset --hard origin/master

(This assumes that you're working on master locally and you want the changes on the origin's master - if you're on a branch, substitute that in instead.)

0 votes
answered Oct 5, 2014 by chand-priyankara

Full sync has few tasks:

  • reverting changes
  • removing new files
  • get latest from remote repository

git reset HEAD --hard

git clean -f

git pull origin master

Or else, what I prefer is that, I may create a new branch with the latest from the remote using:

git checkout origin/master -b <new branch name>

origin is my remote repository reference, and master is my considered branch name. These may different from yours.

0 votes
answered Oct 31, 2016 by j-m-janzen

Simplest version, assuming you're working on the same branch that the file you want is on:

git checkout path/to/file.

I do this so often that I've got an alias set to gc='git checkout'.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter