From Change to Merge: A Narrative Walkthrough for GitHub PRs (git + gh)

Pull requests keep quality high—but they shouldn’t slow you down. This guide walks through a clean, terminal-only flow to make a change, open a PR, pass checks, and merge using git and gh, with the “why” behind each step.

Table of Contents

Pull requests keep code quality high, but the mechanics can feel clunky if you’re bouncing between browser tabs and terminal windows. Here’s a practical, story‑style walkthrough of how I go from “I need to change something” to “it’s merged,” using just git and the GitHub CLI (gh).

We’ll move step by step and explain why each step matters, not just what to type.


Start on a clean base: sync your default branch

Think of your default branch (main in most repos) as home base. Before you branch off to do work, make sure home base reflects the latest truth on GitHub. This avoids drift, surprise conflicts, and flaky CI later.

Why --ff-only? It guarantees your local branch moves forward cleanly without creating merge commits you didn’t intend.


Create a feature branch that tells a story

A good branch name communicates intent at a glance—use short, descriptive slugs like feat/…, fix/…, or docs/…. This keeps your local history tidy and makes the eventual PR easy to understand.

Now you’ve created an isolated workspace. Anything you do here can be reviewed independently and merged without touching main until it’s ready.


Make the change and prove it works

Edit the files, keep saves small, and run whatever tests or linters the repo expects. Small, incremental changes are easier to review and to debug when CI turns red.

If your repo uses a formatter (e.g., pre-commit, eslint, black), run it now so CI doesn’t flag style nits later.


Commit with intent (and sign if required)

A strong commit message explains what changed and hints at why. If your org uses Conventional Commits, follow that shape.

Examples:

  • feat: add renewal threshold flag for Plesk LE automation
  • fix: correct domain autodiscovery when DB fallback is used
  • docs: add cron example with flock

Publish your branch

Push your story to GitHub so others can see it and CI can test it.

The -u sets upstream tracking—future git push/git pull will “just work.”


Open the PR with helpful context

PRs are for humans. Spend a minute to write a clear title and a body that answers three questions: What changed? Why? How did you test it?

A quick sanity check:


Navigate reviews and required checks

Most orgs require at least one approval and passing CI. When CI fails, read the logs, reproduce locally, commit a fix, and push—CI will re‑run automatically.

If the repo says your branch is out of date with the base branch, bring it up to date. Rebasing keeps history linear and is preferred in many teams:

--force-with-lease is the safe variant—it refuses to clobber remote work you don’t have locally.

If your team prefers merge updates instead of rebase:

You can also approve from the CLI (when appropriate):


Merge cleanly, the way your repo expects

Once the green lights are on and approvals are in, merge using the method your repo allows. Squash is common because it keeps main readable.

If you’d rather set it and forget it, enable auto‑merge—GitHub will merge as soon as checks pass:


Land the change locally and tidy up

After the PR merges, bring your local main up to date and remove the working branch.


Working from a fork (no direct push to upstream)

If you can’t push branches to the upstream repo, fork it and send your PR from there.


Quick troubleshooting

  • “Updates were rejected because the remote contains work…” → You’re behind. git pull --ff-only or rebase onto origin/$MAIN before pushing.
  • CI fails on formatting/linting → Run the repo’s formatter/linter, commit, push.
  • DCO / sign‑off requiredgit commit --amend -s --no-edit && git push --force-with-lease.
  • Protected branch / PR required → You can’t push to $MAIN. Always branch and open a PR.
  • “This branch is out‑of‑date with the base branch”git rebase origin/$MAIN (or merge), resolve, push.

That’s the whole journey: start clean, branch with intent, prove your change, communicate clearly, and merge in a way that keeps history readable. With these habits, PR‑required repos feel fast—not fussy.

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.