stop tracking folder from git repository

How to Stop Tracking Folder in Git Without Deleting

Git is a powerful, free, distributed version control system used by software developers and organizations around the world. While using git, you may often need to stop tracking specific files & folders without actually deleting them, in case you don’t want it be a part of future history of your repository. In this article, we will learn how to stop tracking folder in git without deleting it.


How to Stop Tracking Folder in Git Without Deleting

Here are the steps to stop tracking folder in git without deleting.


1. Add Folder Path to .gitignore

First step is to add the folder path to .gitignore file located at the root of you repository. Open .gitignore file in text editor.

$ vi .gitignore

Add the path to your folder (e.g. /data) in .gitignore file. Please make sure the folder path is relative to the root folder of your repository.

/data


2. Remove Folder from Local Tracking

Run ‘git rm’ command to remove the folder from being tracked in your git repository.

$ git rm -r --cached path_to_your_folder/

Here is the command to remove /data from being tracked.

$ git rm -r --cached /data


3. Commit & Push Changes

Commit latest changes with the following command.

$ git commit -am "type your message here"

Push changes to master. Replace <branch_name> below with the name of your branch. For example, if you are pushing to origin, replace <branch_name> with it.

$ git push <branch_name> master

From now on, this folder will not be present in the latest commit or any of the future history. If anyone pulls from this repo, this folder will be removed from their tree. However, it will continue to remain in your working directory since you have used ‘rm -r –cached’ command. If you want to remove it from your working directory also then use the plain old ‘rm -r’ command to delete it.

In this article, we have learnt how to remove folder from git repository.

Also read:

Bash Loop Through Files in Directory & Subdirectories
How to Remove Git Ignore Files from Git Repository
How to Stop Python Code After Certain Amount of Time
How to Convert Bytes to String in Python
How to Store Output of Cut Command in Shell Variable

Leave a Reply

Your email address will not be published.