Git: How to remove files that are now in gitignore but were added to repo before

I have a couple of files that are in the repo and also in .gitignore.

I would like these files to be removed from the repo but not be deleted from my production server when I do git pull origin master

  • How best to handle .classpath files in Git when developers are using different versions of JBoss in their project build paths?
  • Git Commit after merge opens VIM
  • git show to view prior version of a renamed file?
  • Jenkins Version Number Format Substring
  • How do you rollback to a previous Gemfile.Lock?
  • How to bundle install a git gem behind a proxy?
  • I have tried multiple solutions but none seam to work, in each one I end up deleting the files from the server when I do a pull.


    How to make Git "forget" about a file that was tracked but is now in .gitignore?

    Remove directory from remote repository after adding them to .gitignore

    How to remove files that are listed in the .gitignore but still on the repository?

  • Git rebase favor newer changes
  • Git merge conflict since I deleted a file
  • Git post-receive-email: Unknown type of (commit)
  • git-svn: how to copy git commits from one SVN branch to another?
  • Git clueless — please clarify
  • How can I hide the “pr” remote branches?
  • 2 Solutions collect form web for “Git: How to remove files that are now in gitignore but were added to repo before”

    You need git filter-branch first, then ask everybody to rebase branches created off of your old history.

    Refer to:

    This is complex, and might cause issue, so next time be careful so not to get there.

    If you can’t do that due to some reason, then need to wait until time machine invented 🙂

    AFAIK, there is no way to mark a filepath with a “stop tracking this but keep existing version” flag.

    You will need to take one manual action when deploying the first version that includes deleting the file.

    Something like :

    cp file
    git pull
    mv file
    Git Baby is a git and github fan, let's start git clone.