Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Git to overwrite local changes but to keep untracked files

Tags:

git

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?

like image 624
jjei Avatar asked Nov 05 '22 20:11

jjei


1 Answers

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.

like image 88
Kris K. Avatar answered Nov 15 '22 04:11

Kris K.