On my branch I had some files in .gitignore
On a different branch those files are not.
I want to merge the different branch into mine, and I don't care if those files are no longer ignored or not.
Unfortunately I get this:
The following untracked working tree files would be overwritten by merge
How would I modify my pull command to overwrite those files, without me having to find, move or delete those files myself?
You can try command to clear the untracked files from the local
git 2.11 and newer
older git
where -d can be replace with following:
-x means ignored files are also removed as well as files unknown to git.
-d means remove untracked directories in addition to untracked files.
-f is required to force it to run.
here is the link that can be helpful as well.
git merge -f
does not exit, butgit checkout -f
does.This works because you make Git force-checkout the other branch, and thereby force-replace the untracked files with their tracked versions. If you then checkout back to your original branch the tracked files disappear, like in every checkout where files don't exist in the destination branch.
You mention a
pull
command in your answer. Pull is nothing butgit fetch
(acquire the remote history) + an automatic merge of the upstream branch; if you precede the solution above with agit fetch
, and merge the upstream branch, the steps will look as follows.You can try that command
If this is a one-time operation, you could just remove all untracked files from the working directory before doing the pull. Read How to remove local (untracked) files from the current Git working tree? for information on how to remove all untracked files.
Be sure to not accidentally remove untracked file that you still need ;)