Reputation: 2551
I accidentally pushed some files to my remote Git branch. What is the best way to remove those particular files from the remote branch?
Upvotes: 10
Views: 28806
Reputation: 2158
Pull the changes from remote, do a git rm
on your local repository, commit the changes, and again push to the remote. The files will be deleted.
You can check this earlier question on Stack Overflow: How can I delete files in the remote repository?
Upvotes: 10
Reputation: 76887
Since you do not want to push those files to the remote server, but want to keep the copies locally, your best bet is to do git rm
with a --cached
flag.
Basically, do this:
git rm --cached some/filename.ext
git rm --cached -r some/directory/
and then commit and push your changes back using
git commit -m "removing redundant files"
From the manpage for git rm
:
--cached
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
Upvotes: 24