paint-brush
How To Delete Files or Folders From Remote Git Repositoryby@Kiran
2,823 reads
2,823 reads

How To Delete Files or Folders From Remote Git Repository

by KiranNovember 30th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

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.
featured image - How To Delete Files or Folders From Remote Git Repository
Kiran HackerNoon profile picture

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!

References: Remove file or folder only from remote repo

This post was first published on Dev Post by Truemark.