version control - How do I force "git pull" to overwrite local files? -


how force overwrite of local files on git pull?

the scenario following:

  • a team member modifying templates website working on
  • they adding images images directory (but forgets add them under source control)
  • they sending images mail, later, me
  • i'm adding images under source control , pushing them github other changes
  • they cannot pull updates github because git doesn't want overwrite files.

the errors i'm getting are:

error: untracked working tree file 'public/images/icon.gif' overwritten merge.

how force git overwrite them? person designer - resolve conflicts hand, server has recent version needs update on computer.

important: if have local changes, lost. or without --hard option, local commits haven't been pushed lost.[*]

if have files not tracked git (e.g. uploaded user content), these files not affected.


i think right way:

git fetch --all 

then, have 2 options:

git reset --hard origin/master 

or if on other branch:

git reset --hard origin/<branch_name> 

explanation:

git fetch downloads latest remote without trying merge or rebase anything.

then git reset resets master branch fetched. --hard option changes files in working tree match files in origin/master


[*]: it's worth noting possible maintain current local commits creating branch master before resetting:

git checkout master git branch new-branch-to-save-current-commits git fetch --all git reset --hard origin/master 

after this, of old commits kept in new-branch-to-save-current-commits. uncommitted changes (even staged), lost. make sure stash , commit need.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -