How can I delete a file from a remote git repository? I have a file that I just deleted from a local repository, and I want to delete it from its corresponding remote repository.
12 Answers
If you deleted a file from the working tree, then commit the deletion:
git commit -a -m "A file was deleted"
And push your commit upstream:
git push

- 11,987
- 12
- 51
- 99
-
8or `git commit -am "A file was deleted"` – Malloc Feb 26 '13 at 13:20
-
3What about removing it from a remote source? In my case I'd deleted the local files but also added them to the git ignore list at the same time, so when I pushed the commit over the remote files remained in the repo as they weren't being tracked any more. – Nathan Hornby May 14 '14 at 09:14
-
2Before removing any unwanted files, ensure they are not listed in the `.gitignore`. Now move or delete the files out of your source tree that you no longer want on your branch. Then perform: `git add .`, `git status` (to review), `git commit -m "removed files X,Y,Z"`, and then add them back to your `.gitignore` so they never creep into your source ever again. – ecoe Oct 19 '16 at 00:35
Use commands :
git rm /path to file name /
followed by
git commit -m "Your Comment"
git push
your files will get deleted from the repository

- 8,620
- 9
- 54
- 69

- 1,773
- 15
- 12
-
2Just in case anyone wants to delete all the files from the directory, use `-r` option for recursive. So the command will look like `git rm -r /path-to-file-name/` then do the `commit` and `push` as mentioned in the above answer. – Kunal Dethe Sep 15 '14 at 06:13
- If you want to push a deleted file to remote
git add 'deleted file name'
git commit -m'message'
git push -u origin branch
- If you want to delete a file from remote and locally
git rm 'file name'
git commit -m'message'
git push -u origin branch
- If you want to delete a file from remote only
git rm --cached 'file name'
git commit -m'message'
git push -u origin branch

- 2,226
- 22
- 22
-
2If you wish to delete a folder instead, you must replace the first command in all 3 cases with the following: `git rm -r 'file name'` – Loich Apr 19 '21 at 10:11
A simpler way
git add . -A
git commit -m "Deleted some files..."
git push origin master
-A Update the index not only where the working tree has a file matching but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree. Taken from (http://git-scm.com/docs/git-add)

- 10,380
- 8
- 58
- 71
If you pushed a file or folder before it was in .gitignore (or had no .gitignore):
- Comment it out from .gitignore
- Add it back on the filesystem
- Remove it from the folder
- git add your file && commit it
- git push

- 16,299
- 4
- 85
- 85
I know I am late, but what worked for me (total git newbie) was executing the following set of git commands:
git rm -r --cached .
git add .
git commit -am "Remove ignored files and resubmitting files"
To give credit where it is due, here is the link to the source.

- 131
- 2
- 10
if you just commit your deleted file and push. It should then be removed from the remote repo.

- 11,355
- 3
- 53
- 66
If you have deleted lot of files and folders, just do this
git commit -a -m .
git push

- 1,939
- 3
- 30
- 56
Git Remote repository file deletion simple solution:
git commit (file name with path which you want to delete) -m "file is deleted"
git push
It will work.Multiple selective file also you can delete in remote repository same way.

- 305
- 1
- 14
Visual Studio Code:
Delete the files from your Explorer view. You see them crossed-out in your Branch view. Then commit and Sync.
Be aware: If files are on your .gitignore list, then the delete "update" will not be pushed and therefore not be visible. VS Code will warn you if this is the case, though. -> Exclude the files/folder from gitignore temporarily.
The easiest thing to do is to move the file from your local directory temporarily, then commit changes to your remote repo. Then add it back to your local repo, make sure to update .gitignore so it doesn't commit to remote again

- 788
- 8
- 12
Don't need to worry, I just tackled this issue.
Step 1: Use commit changes
$ git commit -a "files were deleted"
Step 2: Push the changes
$ git push

- 3,719
- 8
- 17
- 30