Skip to content

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

GitHub Engineering 10 min read Deep dive mediumAdept

How the GitHub CLI can now enable triangular workflows

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.

Assumes: Git branches and remotesPull requests

Related posts

  • Enabling branch deployments through IssueOps with GitHub Actions

    GitHub Engineering mediumAdept

    GitHub's branch-deploy Action brings the branch deploy model to any repository through IssueOps: comment commands like `.deploy` or `.deploy noop` on a pull request trigger a GitHub Actions workflow that deploys the branch before it is merged. Because changes are deployed and validated before merging, `main` stays stable and rollback means simply redeploying `main`. A sample workflow shows how the action's `continue`, `noop` and `ref` outputs gate deployment steps. The action also respects branch protection, supports deploy locks and configurable environments, and GitHub and npm use it internally, mainly for Terraform infrastructure repos where ChatOps isn't available.

  • Scripting with GitHub CLI

    GitHub Engineering mediumAdept

    GitHub CLI (`gh`) can be extended and scripted by combining it with standard Unix tools. Aliases shorten common commands, PAGER settings route output through `less` or `delta`, and `fzf` plus `cut` turn `gh pr list` into an interactive PR checkout. When output is piped, `gh` emits tab-delimited, untruncated, uncolored text for scripts, and it comes pre-installed in GitHub Actions for tasks like enabling auto-merge or creating releases. `gh api` handles REST and GraphQL calls with auth, pagination, caching and built-in jq filtering, demonstrated by dynamically building a search for issues involving members of a team.

  • Using Github Actions with Railway

    Railway mediumAdept

    Railway deployments can be driven from GitHub Actions instead of the built-in branch-push trigger by creating a project token, storing it as a repository secret (RAILWAY_TOKEN), and running `railway up --service=<id>` inside the official Railway CLI container. A sample workflow triggers on pushes to main, checks out the code and uploads it to Railway. The token must stay secret, but the service ID can be passed openly. The same token approach also works for tasks like running database migrations before deploy or managing pull requests.

  • Working with NX, Railway and CI/CD

    Railway mediumAdept

    A GitHub Actions workflow can deploy only the NX monorepo apps affected by a push to Railway, replacing Railway's built-in GitHub trigger. The setup sets NIXPACKS_NX_APP_NAME, creates one Railway environment and project token per branch, and stores the tokens as GitHub secrets named RAILWAY_TOKEN__<project>_<environment>. On each push the workflow works out a base commit that survives force pushes, then lints and builds the affected projects. A bash script uses `nx print-affected` to find the affected apps, looks up each app's token from a dumped secrets JSON file, and runs `railway up --detach`. Dumping the secrets to a file is flagged as risky in public repos, and `--detach` keeps long container builds from using up GitHub Actions minutes.

  • Building GitHub with Ruby and Rails

    GitHub Engineering mediumAdept

    GitHub's ~2M-line Rails monolith upgrades to the latest Rails main-branch commit every week via a scheduled GitHub Actions workflow that opens an automated PR, runs all builds, and ships the next day. CI also runs a parallel build against the latest Ruby commit, which let GitHub test Ruby 3.2 release candidates on production traffic, catch regressions such as a keyword-argument allocation increase before release, and adopt Ruby 3.2.1 on release day. Benefits include dropping nearly all Rails patches, avoiding big-bang migrations, and better security posture. The approach depends on a thorough test suite and progressive rollout deploys.

The quest for software engineering knowledge.

Look:
Layout: