Delete a single file from remote GitHub repository

Hi there,

I am new to GitHub, and I've gone through a few video tutorials and GitHub help articles, but I still don't think I understand how it works.

Can a single file in my remote GitHub repository be deleted from a GitBash command prompt on my computer?

I've tried this from GitBash:
$ git remote rm https://github.com/myGitHub/myRepository/myFile.zip
 error: Could not remove remove config section 'remote.https://github.com/myGitHub/myRepository/myFile.zip'

Open in new window


The error doesn't sound good, so I assume it's the wrong command??
userTesterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
I think it's easier to remove from your local copy of the repository and then push the changes to the remote. in that case, you'd open a command line and go to the root folder of your local repo. You then have a few options:

If you want to delete the file from the repo, but leave it in the the file system (will be untracked):
git rm --cached myFile.zip
git commit -m "Deleted myFile.zip from the repo"

Open in new window

If you want to delete the file from the repo and from the file system then there are two options:

If the file has no changes staged in the index:
git rm myFile.zip
git commit -m "Deleted myFile.zip"

Open in new window

If the file has changes staged in the index:
git rm -f myFile.zip
git commit -m "Deleted myFile.zip"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
userTesterAuthor Commented:
Thanks MlandaT,

What do you mean by
If the file has no changes staged in the index
?
MlandaTCommented:
Basically... just if the file you are deleting has any changes that havent been pushed/committed.
userTesterAuthor Commented:
Thanks Mlanda, it worked perfectly!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Git

From novice to tech pro — start learning today.