Git - how delete file from remote repository

Git

Git Problem Overview


How can I delete file from remote git repository? I have a file that is just deleted from working copy local repository, and I want delete it from corresponding remote repository

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

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

Solution 3 - Git

  1. If you want to push a deleted file to remote

> git add 'deleted file name' > > git commit -m'message' > > git push -u origin branch

  1. If you want to delete a file from remote and locally

> git rm 'file name' > > > git commit -m'message' > > > git push -u origin branch

  1. If you want to delete a file from remote only

> git rm --cached 'file name' > > > git commit -m'message' > > > git push -u origin branch

Solution 4 - Git

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)

Solution 5 - Git

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

Solution 6 - Git

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

Solution 7 - Git

If you have deleted lot of files and folders, just do this

git commit -a -m .
git push

Solution 8 - Git

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.

Solution 9 - Git

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.

Solution 10 - Git

Visual Studio Code:

Delete the files from your Explorer view. You see them crossed-out in your Branch view. Then commit and Sync.

enter image description here

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.

Solution 11 - Git

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

Solution 12 - Git

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpaganottiView Question on Stackoverflow
Solution 1 - GitjabalView Answer on Stackoverflow
Solution 2 - GitMayank RaipureView Answer on Stackoverflow
Solution 3 - Gitireshika piyumalieView Answer on Stackoverflow
Solution 4 - GitzarpioView Answer on Stackoverflow
Solution 5 - GitChristophe RoussyView Answer on Stackoverflow
Solution 6 - Gitandy bootView Answer on Stackoverflow
Solution 7 - GitArmen ArzumanyanView Answer on Stackoverflow
Solution 8 - GitMo AboulmagdView Answer on Stackoverflow
Solution 9 - GitBharat BhushanView Answer on Stackoverflow
Solution 10 - GitviiView Answer on Stackoverflow
Solution 11 - Gitdave o gradyView Answer on Stackoverflow
Solution 12 - GitAnshul BhattView Answer on Stackoverflow