Remove file from Git without deleting locally

0 min read 115 words

If you find yourself in a position where you have already committed some files to git, and they are in the remote repository already, but you want to remove them from you repository without deleting them locally, you can do the following:

Introducing the git rm --cached command:

Remove a folder from Git

git rm --cached -r FolderName

Remove a file from git

git rm --cached SomeFile.ext

And then what?

Now that the files have been removed from the local git cache, you should probably either commit the changes you’ve made, or add an entry to your local .gitignore file and then commit the changes.

This will make sure that it does not happen again.

Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags

Recent Posts