Git
GxP
Best practices
Foundations series · part 2

Git workflow: branches, squash-only merges, signed commits

A boring, predictable path from idea to main

A predictable branch-and-PR workflow for R teams with branch protection, squash merges, and signed commits.
Published

2026-09-26

Modified

2026-09-27

The problem

Solo R work often happens straight on main: edit, commit, push. It works until two people touch the same package, a half-finished change reaches a user, or someone asks “who approved this change, and what tests ran?”

A small workflow fixes all three, and every piece of it has an R-native helper.

The workflow

main ──●───────────────●──────────  (always releasable; one squash commit per PR)
        \             /
         ●──●──●──●──●   feat/km-risk-table  (messy commits are fine here)
                      └─ PR: title "feat(km_plot): add risk table", CI green, reviewed
  1. Branch from an up-to-date main, one branch per issue: feat/…, fix/…, docs/….
  2. Commit freely on the branch.
  3. Open a PR. CI runs, someone reviews, and the PR title follows Conventional Commits.
  4. Squash-merge. The branch becomes one commit on main, and the branch is deleted.

The web-repo way: repo settings

gh api -X PATCH repos/OWNER/REPO \
  -F allow_squash_merge=true -F allow_merge_commit=false -F allow_rebase_merge=false \
  -F delete_branch_on_merge=true \
  -f squash_merge_commit_title=PR_TITLE -f squash_merge_commit_message=PR_BODY
Setting Why
Squash only Linear history, where one commit is one reviewed change. git revert <sha> undoes a whole feature.
Title = PR title The commit message is the reviewed, conventional title
Auto-delete branches No graveyard of stale branches

Branch protection: check your plan

Branch protection and rulesets are what enforce “no direct pushes to main” and “CI must pass”. On GitHub Free they only work on public repos. We checked a private repo on a free account, and the API answered: “Upgrade to GitHub Pro or make this repository public to enable this feature.”

On a private free repo you have two options: follow the workflow by convention (and say so in CONTRIBUTING.md), or upgrade. On Team or Enterprise plans, turn on: require a PR, require status checks (R-CMD-check), require linear history, and block force-pushes.

Signed commits

user.email is just text; anyone can type yours. A signature proves a commit came from a key you control, and GitHub then shows Verified. SSH signing reuses the kind of key you already push with:

[gpg]
    format = ssh
[user]
    signingkey = ~/.ssh/id_ed25519_work.pub
[commit]
    gpgsign = true
[tag]
    gpgsign = true

Add the same public key to GitHub a second time, as a Signing key. The Authentication key entry doesn’t cover signing.

Note“No signature” locally doesn’t mean unsigned

After enabling signing, git log --show-signature printed “No signature” with an error about gpg.ssh.allowedSignersFile. The commit was signed: git cat-file -p HEAD showed a BEGIN SSH SIGNATURE block, and GitHub marked it Verified. Git simply had no list of keys to trust locally. Fix:

echo "you@users.noreply.github.com $(cut -d' ' -f1,2 ~/.ssh/id_ed25519_work.pub)" > ~/.ssh/allowed_signers
git config gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers

Now git log --show-signature reports Good “git” signature.

For GxP, signed commits plus PR review are strong evidence of who made a change and who approved it. The same ALCOA+ Attributable point comes up in identity and environment isolation.

The R way: usethis::pr_*()

usethis wraps the whole loop, so you never need to remember the git commands:

usethis::pr_init("feat-km-risk-table")  # branch from an up-to-date default branch
# ... edit, commit (RStudio/Positron Git pane is fine) ...
usethis::pr_push()                       # push and open the PR page in the browser
usethis::pr_pull()                       # pull reviewer changes
usethis::pr_merge_main()                 # bring in new commits from main
usethis::pr_finish()                     # after merge: delete local branch, back to main
usethis::pr_fetch(42)                    # check out someone else's PR #42 to review it

Squash-merge in the GitHub UI, or with gh pr merge 42 --squash. The IDE Git panes call your system git, so signing configured in git applies to IDE commits too.

Pitfalls

  • git pull merge commits. Set git config --global pull.rebase true.
  • Long-lived branches drift and conflict. Keep PRs small, and use pr_merge_main() often.
  • Squash hides branch history on main. That’s the point: the PR keeps the detail.
  • Signing key on a new machine. Signing fails until the key and config exist, so set it up once per machine (identity and environment isolation).

Sources

Git and GitHub

R package documentation

  • usethis (pr_init(), pr_push(), pr_pull(), pr_merge_main(), pr_finish(), pr_fetch()): usethis.r-lib.org
NoteUpdates
  • 2026-09-26: Removed the end-of-post checklist.
  • 2026-09-27: Added a Sources section.