Search code examples
gitgithubatlassian-sourcetree

Git refuses to pull after .gitignore change


Git won't allow me to pull some commits. I must add that one of those commits has a .gitignore change adding some files to it.

When I try to pull the commits it says that I have local changes to the same files that were added to .gitignore. but I cannot find any local changes, git status, git diff, source tree, all show no local change.


Solution

  • First, if you have added files to .gitignore, make sure to have remove them as well, otherwise they would still be tracked.

    git rm --cached -- anIgnoredFile
    git commit -m "record file deletion/ignore"
    

    Second, when you pull, try a rebase instead of a merge, which you can automate with:

    git config --global pull.rebase true
    git config --global  rebase.autoStash true
    

    Then try again your git pull: this time it should re-apply your local changes on top of the updated history.