I accidentally pushed some files to my remote Git branch. What is the best way to remove those particular files from the remote branch?
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With