It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to delete a file/folder from Bitbucket repository?

eiger3970 May 09, 2014

Hi, I'm a Bitbucket noob and having a hard time getting started.

I'm trying to clean up the Bitbucket repository and my local git folder master and branch organisation.

My local computer's git folder has some folders deleted via Terminal $ rm -r folderName > $ git push.

Bitbucket repository still shows the folderName. How do I remove this?

I think part of the mess started with my local machine git cloning to the git folder which was in branch status and not master status?

10 answers

1 accepted

5 votes
Answer accepted
eiger3970 May 29, 2014

Ok, I figured out how to do it.

It seems you can't delete a remote file from a local command.

I went to the remote repository's website > Source > select branch > select folder > select file to be deleted > Edit > Delete > Commit.

Sean Seymour May 15, 2018

As far as I can tell, this doesn't work for folders - only files.

Like # people like this
Kresimir Nurnberger Sep 18, 2018

This post worked for me. 

https://stackoverflow.com/questions/6313126/how-to-remove-a-directory-from-git-repository/6313301#6313301

The question should be: "How to delete folders/files with git?"

Not in bitbucket.

Like # people like this
1 vote
eiger3970 May 10, 2014

Thank you for the reply. The links are easy to read which is a nice improvement for IT documentation.

My issue isn't about deleting a branch however.
The issue is folder/s in the remote Master and a folder in the remote branch that won't delete.
I have deleted files locally and remotely in Master and Branch, but not the folders.

I think I'm misunderstanding how the Master and Branch works.
I have pulled the remote Master and then created a Branch locally. I then pushed the local Master and local Branch to the remote repository.
I'm confused on where the local folder is for my local Master and local Branch?
I have a git working folder/directory, but in there the folders 'magically' appear and disappear when I change to local Master or local Branch via Terminal?
I would like to always have access to seeing my local folders' Master or Branch, regardless of whether I'm in Terminal local Master or local Branch.

1 vote
Adam Tahri Apr 01, 2015

I have an issue
I can delete a file parsable by Bitbucket (text, image, ...)
But for the others files (exe, ...) I can not delete it. When I click on the file, my browser download it

0 votes
eiger3970 May 11, 2014

I have now deleted all files within the master folder named webpage.

However one remaining hidden file won't delete, named: .DS_Store

I think this is stopping the folder webpage being deleted?

Casey Wise Sep 13, 2018 • edited

Hi @eiger3970 the .DS_Store file is a hidden file used by OSX to store user preferences and other "meta" info.  Wikipedia lays it out better than I can.  You don't want the file in your code base.  Remove + commit in your terminal:

rm -f .DS_Store && git commit -am "file clean up"

 

Like Hunter Rafuse likes this
Hunter Rafuse Apr 17, 2019 • edited

This worked the best for me yet I did it in separate lines, for example(example not literal to the scenario listed above but should help):


within this gitignore add what you want to ignore like so -> node_modules
then save make sure you mash cmd + s because mac isn't sensitive to be fair.

$ touch .gitignore

 

After creating the .gitignore and saving, remove that folder(or file). Like below:

$ cd repository_root
$ rm -rf node_modules 

 

Then it will spit out red sentences don't worry this is just a notification about a change within the repository locally, but the lines 
should start with  deleted to notify the change in the repository.
Now let's wrap this up by adding. committing and then pushing all of our changes.

$ git add .

$ git commit -m "File cleanup, removal of node_modules and then adding of .gitignore"

$ git push

 

Zmi nazim Apr 23, 2019

I had same exact situation. When I tried git rm -r myFolder it worked, but also deleted everything from "MyFolder" directory. Had to revert everything in the "MyFolder" directory and then commit.

Lucky Patcher 9Apps VidMate

0 votes
eiger3970 May 11, 2014

Well, maybe the remote repository was slow or I made a mistake.

It seems the folders are now deleted so I can work with a cleanly organised local and remote repository now. See how it goes over the next few weeks.

0 votes
eiger3970 May 29, 2014

I have the same problem again about deleting a file off the Bitbucket online remote repository.

I made a local file with the wrong name and pushed it up to the Bitbucket online remote repository.

I have now renamed the wrong named file on my local computer and deleted the wrongly named file.

I then typed $ git add fileWithWrongName.* fileWithCorrectName.* > Enter > $ git commit -m "Deleting wrongly named file and adding new correct named file on Bitbucket online remote repository." > Enter > $ git push > Enter > $ <Bitbucket password> > Enter.

The new file fileWithCorrectName.* was pushed up successfully to the Bitbucket online remote repository, however the fileWithWrongName.* didn't delete/remove from the Bitbucket online remote repository?

Any suggestions please?

0 votes
sjfn fdjjjj I'm New Here May 02, 2019

try delete > commit 

http://www.floorchair.org/

0 votes
Bhavya Sharma I'm New Here May 15, 2019 • edited

so my suggestions are: 

- move the file/folder you want to delete in your computer to another folder from your master folder...

then type on your terminal..

- git commit         ( this commits the changes like when you move the folder to another

destination, this will commit only the files or folders present in that master folder)

then ..

- git push       ( this will push the final layout of your folder)

now you can refresh your repo and see updated commit

Result: you see only files and folders you have in your master folder.

Thank you

Bhavya Sharma

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

3,029 views 1 20
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you