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 t
git merge that will overwrite untracked filesThe comments below use 'FOI' for the 'files of interest', the files that
git checkout -f donor-branch # replace FOI with tracked `donor` versions
git checkout receiving-branch # FOI are not in `receiving`, so they disapppear
git merge donor-branch # now the merge works
git pull that will overwrite untracked filespull = fetch + merge, so we do git fetch followed by the git checkout -f, git checkout, git merge trick above.
git fetch origin # fetch remote commits
git checkout -f origin/mybranch # replace FOI with tracked upstream versions
git checkout mybranch # FOI are not in mybranch, so they disapppear
git merge origin/mybranch # Now the merge works. fetch + merge completes the pull.
git merge -f does not exist, but git checkout -f does.
We will use git checkout -f + git checkout to remove the Files Of Interest (see above), and then your merge can proceed normally.
Step 1. This step forcibly replaces untracked FOI with tracked versions of the donor branch (it also checks out the donor branch, and updates the rest of the working dir).
git checkout -f donor-branch
Step 2. This step removes the FOI because they they are tracked in our current (donor) branch, and absent in the receiving-branch we switch to.
git checkout receiving-branch
Step 3. Now that the FOI are absent, merging in the donor branch will not overwrite any untracked files, so we get no errors.
git merge donor-branch