Skip to content

Forked repo, PRs, and squashed commits

Liz Dobbins edited this page Jul 25, 2024 · 2 revisions

For development purposes, it sometimes makes sense to fork the production repo and work on a development fork. This allows us to trigger GitHub Actions in order to test workflow builds and deployments while preserving the production deployment. Development happens in the development fork, and changes are pulled into the production repo via a Pull Request.

This is well and good with one exception: development and testing deployments can lead to a pile of commits, especially during heavy debugging. When the PR comes into the production repo, it brings along every commit, cluttering up the commit history. For this reason, we really want to eliminate the chaff and leave only the wheat. We can do this by using git squash during the merge.

There are ways to accomplish this manually in your local repo, but the process is streamlined dramatically by GitHub's web interface. Here are the steps:

  1. Develop on your forked repo, pushing to main in order to trigger the GitHub build and deploy. When you're ready to ship changes, branch main into pr-feature-name. This allows development on the forked main to continue while awaiting the PR merge. Otherwise, the PR will try to add ongoing commits. This makes a mess. Once the branch pr-feature-name is created, don't touch it!

  2. Make a PR of the new branch, comparing pr-feature-name to main in the production repo.

  3. Review and (have someone else) Approve the PR.

  4. Reviewer: Once the PR is ready to be merged, click "Merge pull request" to open the merge options.

  5. In the dropdown menu that appears, you have several merge options. Select "Squash and merge". This will combine all the commits from the PR into a single commit.

  6. Edit Commit Message : GitHub will automatically create a commit message for the squashed commit, including the titles of all squashed commits. Delete this and write a single commit message that explains the PR.

  7. Click the "Squash and merge" button to confirm. GitHub will squash all the commits from the PR into a single commit and merge it into your main repository.

Warning

If you have lingering HTML files in your main branch from local renders, the GitHub action step will queue and never run. Dunno why. Just make sure to remove all those rendered files, or make sure they are in a directory that is listed in .gitignore so they are not uploaded to GitHub.