Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Deleting a specific directory from repo doesn't work

Paras Gorasiya September 4, 2019

I am trying to remove a specific directory from my repo.

So I first added that directory into .gitignore and ran 

git rm -r --cached <directory name>

into terminal and committed changes and push.

But when I check on my repo, that folder is still there.

I dont understand why its still there.

I want to keep it on local but just want to delete that directory from repo and ignore all commit related to that directory for future.

What should I do?

1 answer

1 accepted

1 vote
Answer accepted
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 5, 2019

Hi Paras, welcome to the Community!

First of all, please note that this is a Git question and not a Bitbucket question, but I'll try to help you anyway.

You said you're trying to remove a directory but that after running git -rm the directory is still there. Can you check if there are any contents inside the directory? If the directory is empty, then that's the expected behavior. Git doesn't handle directories, it handles files. You can learn more about this in the Git FAQ:

Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it.

Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own.

You can say "git add <dir>" and it will add the files in there.

If you really need a directory to exist in checkouts you should create a file in it. .gitignore works well for this purpose (there is also a tool MarkEmptyDirs using the .NET framework which allows you to automate this task); you can leave it empty or fill in the names of files you do not expect to show up in the directory.

The same happens when you try to remove it. There are no files to be removed, so there's nothing to remove. 

If you don't want the empty directory to be there, you can remove it manually.

Hope this adds some light into the situation!

Best regards,

Ana

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events