Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Render 5 min read How-to mediumAdept

Git Organized: A Better Git Flow

Commit-as-you-go branches often produce commits mixing unrelated or half-finished changes, which makes reverts risky and pull requests tedious to review. A cleaner flow is to do the work first with throwaway WIP commits, then `git reset` back to the branch point (keeping the working tree), and rebuild logically grouped commits using `git add -p` for partial files. Verify that each new commit works on its own by stashing the remaining changes and testing, and use `git commit --amend` to fix up omissions. If anything goes wrong, `git reflog` can recover the original commits.

Assumes: basic git commandspull request workflow

Related posts

  • On the Importance of Pull Request Discipline

    Shopify Engineering mediumAdept

    Well-structured pull requests make code review easier and leave a self-documenting history that speeds debugging and rollbacks. The guide walks through each part of a GitHub PR: titles that state scope and affected models, summaries that explain what changed and why, including alternatives considered, plus commit messages, comments, labels and linked issues. For commits it recommends that each one pass CI on its own, follow a logical order, keep refactors separate from business logic, fold linter and review fixes in with fixup/autosquash, and include tests with the code they cover. It also favors smaller PRs and accepts skipping the rules during emergencies, provided the history is cleaned up afterwards.

  • Merging two GitHub repositories without losing commit history

    Mozilla Hacks mediumAdept

    MDN merged small example repositories into a larger parent repo while keeping full commit history, using only plain git commands. First, inside the source repo, all files move into a subdirectory matching the target layout (using zsh extendedglob negation like `mv ^(sw-test|service-worker)`, with hidden files moved separately so `.git` stays put). That change is merged, then the source is added as a remote in the target and merged with `git merge --allow-unrelated-histories`, resolving add/add conflicts such as README.md.

  • WebKit on GitHub!

    WebKit easyNovice

    WebKit froze its Subversion tree on June 23rd and moved source control to git hosted on GitHub, citing git's distributed collaboration model, its author/committer model, cheap branch and revert operations, and the fact that most contributors already worked from git-svn mirrors. GitHub was chosen for its developer community and an API that made pre- and post-commit automation easy to build. Because git hashes are unordered, which complicates bisection under WebKit's zero-tolerance performance regression policy, the project uses "commit identifiers": the ancestor count on main (git rev-list --count) plus a branch-relative count for branches. These identifiers are supported by the git-webkit script and the commits.webkit.org translation service.

  • How the GitHub CLI can now enable triangular workflows

    GitHub Engineering mediumAdept

    GitHub CLI v2.71.2 makes `gh pr` commands resolve a branch's push and pull targets the same way Git does, so triangular workflows work. In a triangular workflow a branch pulls from one ref, such as upstream's default branch, and pushes to another, such as the same-named branch on a fork. The post shows how to set this up in `.git/config` with a branch's `merge` key, the per-branch `pushremote` key, or the repo-wide `remote.pushDefault`, and notes that `pushremote` overrides `remote.pushDefault`. To find a pull request's headRef, the CLI checks `@{push}` first, then `pushremote`, then `remote.pushDefault`, and it treats the branch's pullRef as the PR's baseRef, so if `git push` and `git pull` are configured correctly, `gh pr` should just work.

  • Code Review Can Be Better

    TigerBeetle mediumAdept

    TigerBeetle shelved git-review, an experiment that stored code review as a single commit of inline marked comments on top of the PR branch, edited by author and reviewer and reverted once all threads were resolved. Reviewing locally with inline comments worked very well, but applying requested changes caused merge conflicts with review comments at hunk boundaries, and frequent force-pushes added friction. The mismatch between strict hash-chained history for code and the looser merging review needs pushed the tool past a small-script budget. Git's possible adoption of Gerrit-style Change-Ids may enable per-commit interdiff review, and related tools such as Fossil, git-appraise, prr and flirt are listed.

The quest for software engineering knowledge.

Look:
Layout: