How To Delete Files or Folders From Remote Git Repository

Written by Kiran | Published 2020/11/30
Tech Story Tags: git | github | gitlab | git-tags | git-basics | tutorial | guide | version-control | web-monetization

TLDRvia the TL;DR App

GIT is great, it has made collaboration with other developers so easy, I can’t thank GIT enough. But GIT is vast and not every command remains on my mind. I find myself googling over and over again to get that right GIT command that can solve my problem.
Recently when working on one of the projects that had just started, I accidentally pushed the IDE folder to the remote repository and I was there googling again, so I thought, why not write a blog for this? I can always come straight to my blog if this happens again and I can also help my fellow developers this way, right?
All sensitive information and IDE related folders should be added to gitignore so they are not tracked by git. You may already know this, but it doesn’t help if your file or folder is already in the remote repository. Today we will learn how we can remove files or folders from remote repositories. Let’s get started!

Remove file or folder from remote repo only

# Remove a single file
git rm --cached password.txt

# Remove a single folder
git rm --cached -rf .idea

Remove file or folder from both remote repo and local

After removing a file or a folder, we shouldn’t forget to add them to gitignore before we commit and push to the repo again. Or we will be back to the start of the blog removing those again!
Straight and sweet, that’s it. Any confusions? Have a better solution? Please comment below, it’s never a bad idea to have a healthy conversation. Thank you. See you again!
This post was first published on Dev Post by Truemark.

Written by Kiran | Content Writer at Truemark Technology. Company Website Link - https://www.truemark.dev/
Published by HackerNoon on 2020/11/30