Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How do I force an overwrite of local files on a git pull?

The scenario is the following:

  • A team member is modifying the templates for a website we are working on
  • They are adding some images to the images directory (but forgets to add them under source control)
  • They are sending the images by mail, later, to me
  • I'm adding the images under the source control and pushing them to GitHub together with other changes
  • They cannot pull updates from GitHub because Git doesn't want to overwrite their files.

This is the error I'm getting:

error: Untracked working tree file 'public/images/icon.gif' would be overwritten by merge

How do I force Git to overwrite them? The person is a designer - usually, I resolve all the conflicts by hand, so the server has the most recent version that they just need to update on their computer.

like image 507
Jakub Troszok Avatar asked Jul 14 '09 14:07

Jakub Troszok


People also ask

How do I allow git to overwrite local files on pull?

Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.

Does git pull overwrite new files?

The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.

Will git pull erase my local changes?

No - it only changes the repository, tags snd remote heads - it never changes the working tree, local branches or the index. git pull can change local branches, the local tree and the index. It won't overwrite charges but may do a merge, a rebase or fail if there are conflicting changes.

Does git pull merge or overwrite?

git pull --force 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 we want to work on.


0 Answers