I have added a file named \"file1.txt\"
to a Git repository. After that, I committed it, added a couple of directories called dir1
and dir2
First, if you are using git rm, especially for multiple files, consider any wildcard will be resolved by the shell, not by the git
command.
git rm -- *.anExtension
git commit -m "remove multiple files"
But, if your file is already on GitHub, you can (since July 2013) directly delete it from the web GUI!
Simply view any file in your repository, click the trash can icon at the top, and commit the removal just like any other web-based edit.
Then "git pull
" on your local repo, and that will delete the file locally too.
Which makes this answer a (roundabout) way to delete a file from git repo?
(Not to mention that a file on GitHub is in a "git repo")
(the commit will reflect the deletion of that file):
And just like that, it’s gone.
For help with these features, be sure to read our help articles on creating, moving, renaming, and deleting files.
Note: Since it’s a version control system, Git always has your back if you need to recover the file later.
The last sentence means that the deleted file is still part of the history, and you can restore it easily enough (but not yet through the GitHub web interface):
See "Restore a deleted file in a Git repo".
First,Remove files from local repository.
git rm -r File-Name
or, remove files only from local repository but from filesystem
git rm --cached File-Name
Secondly, Commit changes into local repository.
git commit -m "unwanted files or some inline comments"
Finally, update/push local changes into remote repository.
git push
Incase if you don't file in your local repo but in git repo, then simply open file in git repo through web interface and find Delete button at right corner in interface. Click Here, To view interface Delete Option
If you want to delete the file from the repo, but leave it in the the file system (will be untracked):
bykov@gitserver:~/temp> git rm --cached file1.txt
bykov@gitserver:~/temp> git commit -m "remove file1.txt from the repo"
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:
bykov@gitserver:~/temp> git rm file1.txt
bykov@gitserver:~/temp> git commit -m "remove file1.txt"
If the file has changes staged in the index:
bykov@gitserver:~/temp> git rm -f file1.txt
bykov@gitserver:~/temp> git commit -m "remove file1.txt"
In my case I tried to remove file on github after few commits but save on computer
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch file_name_with_path' HEAD
git push --force -u origin master
and later this file was ignored
To delete a specific file
git rm filename
To clean all the untracked files from a directory recursively in single shot
git clean -fdx