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" commits and shuffling branches.
And so this workflow was born.
-
Leverages git worktree to have multiple branches within the same cloned repo.
-
Relies on GH CLI to easily checkout PRs the same way as branches.
-
Uses simple git hook to populate common project settings into new PR directory (optional)
├── dev-settings # (1)
└── main # (2)
-
Common project settings, usually files globally
.gitignore`d. I use this to add my `.autoenv
,tools-version
and other `.gitignore`d utilities, so I have consistent set up across the PRs without manual steps. -
Cloned repository, main branch, where you would usually work.
For the main
folder, once you put your dev-settings
in the new location, you have to populate them
`find ../dev-settings -type f -exec ln -s '{}' . `
This step is only needed once, for subsequent PR projects it is automated (TODO: add "hook" for clone)
Now, from the main
folder we can add PR worktrees using special alias:
❯ git worktree-add-pr 402
remote: Enumerating objects: 2, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 2 (delta 1), reused 1 (delta 1), pack-reused 1
Unpacking objects: 100% (2/2), 258 bytes | 258.00 KiB/s, done.
From github.com:opendatahub-io/opendatahub-operator
* [new ref] refs/pull/402/head -> pr-402
Switched to branch 'pr-402'
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
Preparing worktree (checking out 'pr-402')
HEAD is now at 1a90cd0 Allow multiple component names for Dashboard
Setting up the worktree...
This updates directory structure:
├── dev-settings
├── main
└── pr-402
Now you can open pr-402
as a project in your IDE of choice and you can comfortably walk through the code, hack suggestions and run tests!
To remove, just call regular git command git worktree remove -f pr-402
git config --global alias.worktree-add-pr "!f() { gh pr checkout $1 -b pr-$1; git co -; git worktree-add pr-$1; }; f"
#!/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 '{}' . \;
fi
exit 0