Skip to content

Instantly share code, notes, and snippets.

@bartoszmajsak
Last active February 16, 2024 09:56
Show Gist options
  • Save bartoszmajsak/c68abb2bb99367a1b54e748c996eae1a to your computer and use it in GitHub Desktop.
Save bartoszmajsak/c68abb2bb99367a1b54e748c996eae1a to your computer and use it in GitHub Desktop.
GH PR workflow

Motivation

Most of the times, when PR is not trivial in scope and size, Web UI can often lead to loosing focus and context while scrolling down through the blog of changes. It’s way more efficient to go through the code in the IDE.

I got tired of stashing changes, creating "wip" commints and shuffling branches.

And so this workflow was born.

How it works

  1. Leverages git worktree to have multiple branches within the same cloned repo

  2. Relies on GH CLI for dealing with PR branches

  3. Uses simple git hook to populate common project settings into new PR directory (optional)

  4. I use this to add my .autoenv, tools-version and other git-ignored utilities, so I have consistent set up across the PRs without manual steps.

Pre requisites

Git configuration

git config --global alias.worktree-add-pr "!f() { gh pr checkout $1 -b pr-$1; git co -; git worktree-add pr-$1; }; f"
.git/hooks/post-checkout
#!/bin/bash

previous_head="$1"
new_head="$2"
checkout_type="$3"

if [ "$previous_head" = "0000000000000000000000000000000000000000" ]; then
    echo "Setting up the worktree..."
    find ../dev-settings -type f -exec ln -s '{}' . \; // (1)
fi

exit 0
  1. folder in the main project directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment