Remove file from the repository but keep it locally

I have a folder which I’d like to remove in my remote repository. I’d like to delete it, but keep the folder in my computer

  • how to revert in Git?
  • How do I enable ident string for Git repos?
  • Could I change my name and surname in all previous commits?
  • Git seeing imaginary files (case sensitivity)
  • How to colorize git push output
  • Alternatives to Git for Minecraft server backup/version control
  • Does git “dirty” mean files not staged, or not committed? (glossary conflict)
  • Git log to get commits only for a specific branch
  • bitbake git fetcher failure
  • git-gui reports it has 256 loose objects each time is run and suggests compression which goes fine. How to fix it?
  • Git PowerShell Cmdlets returning git info as objects
  • Is a git commit hash trustable?
  • 2 Solutions collect form web for “Remove file from the repository but keep it locally”

    git rm --cached -r somedir
    

    Will stage the deletion of the directory, but doesn’t touch anything on disk. This works also for a file, like:

    git rm --cached -r somefile.ext
    

    Afterwards you may want to add somedir/ or somefile.ext to your .gitignore file so that git doesn’t try to add it back.

    I would just:

    • Move the folder out of your working tree
    • git rm the folder, commit the change
    • Add to .gitignore (or .git/info/excludes), commit the change
    • Move the folder back
    Git Baby is a git and github fan, let's start git clone.