You can retroactive remove the files if you want, but there are caveats. For a small repo that only you access, it's no big deal; the larger the repo (mostly meaning number of commits) or the more people who use it, the bigger the potential hassle.
The basic procedure would look something like this:
1) Everyone who has a copy of the repo should commit and push any changes they want to preserve. These don't have to be merged, but they should be pushed to origin. (Any change not in origin would have to be migrated after the fact - a procedure that is straightforward but not trivial - or simply redone.) Everyone should then pause development and discard their local clones of the repo.
2) Perform the history rewrite. For a small repo this could be done with git filter-branch
using an index filter like git rm --cached --ignore-unmatch -- <pathspecs>
. A faster option, especially for large repos, would be the BFG repo cleaner.
(There are good usage documents for both of these options, so I won't go into great detail about both of them just now. But if you have specific follow-up questions feel free to ask of course.)
Whichever tool you use will "rewrite history" in your repo. This means that the existing commits - likely all of them based on your use case - will be replaced with new commits. (By "new commit" I mean the commits will have new SHA1 identifiers and git will not recognize them as being related to the old commits.) This is why everyone had to ditch their old clones.
3) Publish the rewritten origin (by whatever means you had previously published the original).
Everyone can now clone the rewritten repo and work can resume.
Honestly it's a pretty drastic step. It's good to know you can do it if someone accidentally commits a file containing a password or other sensitive information. Or if you can actually save considerable space in the repo by removing unwanted content like copies of dependencies. For this... I wouldn't think it's worth it.
To just remove the files from subsequent commits (so that .gitignore can be effective) the command you're using should work, assuming you're in the directory that contains the bin/
directory.