What to do when your commit fails GitHub checks?

Viewed 999

Okay, I just learned about unit testing, GitHub checks with CircleCI and pull requests all in a day. I ran into a question as I was trying to test my understanding of everything:

  1. I've got a repository locally and it is set to push changes to my repo on GitHub.
  2. I've got some basic tests written that pass pytest test runner locally.
  3. I make some simple change to test everything, commit and push the change.
  4. I go to GitHub and see that I did not pass my tests defined in my CircleCI YAML file because I don't have flake8 installed in my virtual environment (I accidentally installed it globally).
  5. I return to PyCharm and install flake8 in my venv.
  6. I update my requirements.txt to reflect the install.
  7. ???

Now, my question is this: When a check fails, what is the best practice for 'updating' the pull request after fixing the issue. Do I just make a new commit that fixes it and start a new pull request? Or, do I find a way to revert the old commit to include the new version that works?

1 Answers

A pull request is a draft branch. Before it's merged to the target branch, it's not really published. You can do whatever you want to, as long as its final revision is as expected. Its commit history might look ugly but it keeps a record of what you have done for a target. People may prefer a more good-looking history even if it's a draft. In that case, one can use git rebase -i, git reset --hard, git commit --amend or even git filter-branch to rewrite a neat and nice history, and then use git push -f to update the pull request. Of course, if others are also working on the same pull request, always notify them before you want to force-update the pull request. On the other hand, if it's squash-merged to the target branch, its history, no matter if it's ugly or good-looking, will not be introduced to the target branch.

Related