7

Once in a while when I do git pull I start getting this error: error: Untracked working tree file [some file] would be overwritten by merge.

I normally want to overwrite the local changes so I do this:

git reset --hard HEAD
git clean -f -d
git pull

This was instructed here: How do I force "git pull" to overwrite local files?

However, this method seems to erase all the untracked files. So is there a way to force git to overwrite local channges but to keep all the untracked files?

Community
  • 1
  • 1
jjei
  • 1,180
  • 3
  • 13
  • 21

2 Answers2

2

git clean -f -d will delete untracked files, so if I understand what you're trying to do, you'll want to skip that and just do git reset --hard HEAD followed by git pull.

Kris K.
  • 998
  • 9
  • 7
0

If you are going to add these untracked files to your working tree, then you can add them to the working tree. When you want to pull changes from origin you can stash them away and do a pull. After the pull you can pop your stash.

yasouser
  • 5,113
  • 2
  • 27
  • 41