My first experience with Git and servers was when we had a server where the only way to get code onto it was to push to Github which then had the server do a pull through a webhook. We ended up with a lot of tiny commits with messages such as "Fix previous commit - commit #3" and "Fix attempted fix for commit #3" because we had no way of knowing whether or not our commits would run properly on the server until after they were committed and pushed.
Recently I deployed my first Rails app to Heroku and although I see a lot of positives there it seems to me to be very similar to the situation I described above. Unless we want to set up our own server to mirror the Heroku servers very closely so that we can upload and test code without committing to Git, there's no way of knowing whether or not our code works until it's already committed, and therefore it might require many small, useless (as far as the repo's history is concerned) "tweak" commits to patch up failed commits.
I know that there are plenty of questions already that explain how to set up and use a staging server in addition to a production server, but that still doesn't solve the problem of polluting the repo history. I know that it's possible to ammend commits, squash, rebase, etc. so that these "useless" commits could be dealt with (as mentioned in the answers to this question), but with multiple people potentially doing this all at once I can see it getting ugly and creating all sorts of conflicts in Git.
TL;DR
How can we maintain a "clean" Git history for our projects when using Heroku so that we don't have a whole slew of commits or branches creating confusion and noise just for the sake of fixing something that should have worked in the first place but didn't simply because we couldn't test it in the server environment until after committing and pushing?