Use when needing to make custom edits to an open source dependency, library, framework, extension, or plugin - handles forking, patching, and push. Also suggest when editing installed open source code or vendored dependencies.
Systematically fork, patch, and maintain custom changes to open source dependencies.
Core principle: Custom commits go directly on the fork's default branch (main or master). Sync with upstream via git fetch upstream && git merge or GitHub's built-in "Sync fork" button.
Announce at start: "I'm using the forking-for-custom-patches skill to set up a maintainable fork."
When NOT to use:
# Verify required tools
command -v gh || echo "STOP: Install gh CLI first"
command -v git || echo "STOP: Install git first"
gh auth status || echo "STOP: Run gh auth login first"
Determine the full owner/repo of the dependency to fork.
# If you're already in a clone:
UPSTREAM=$(git remote get-url origin | sed 's|.*github.com[:/]||;s|\.git$||')
# Or from a known package - ask user to confirm:
# "The upstream repo appears to be <owner/repo>. Is that correct?"
Always confirm with the user before forking.
# Fork to user's GitHub account
gh repo fork "$UPSTREAM" --clone=false
# Determine fork name
FORK_OWNER=$(gh api user --jq '.login')
FORK_REPO="$FORK_OWNER/$(basename "$UPSTREAM")"
If already forked, gh repo fork will report the existing fork. Continue with it.
gh repo clone "$FORK_REPO" "$HOME/git/$(basename "$UPSTREAM")"
cd "$HOME/git/$(basename "$UPSTREAM")"
# Verify upstream remote exists
git remote -v | grep upstream || git remote add upstream "https://github.com/$UPSTREAM.git"
# Determine upstream's default branch
UPSTREAM_DEFAULT=$(git remote show upstream | sed -n 's/.*HEAD branch: //p')
Work directly on the fork's default branch (usually main or master — matching upstream's default branch).
git checkout "$UPSTREAM_DEFAULT"
Apply the needed edits. Commit with a clear message:
git add -A
git commit -m "custom: <description of patch>
Upstream: $UPSTREAM
Reason: <why this patch is needed>
"
git push origin "$UPSTREAM_DEFAULT"
Fork ready:
Fork: https://github.com/<FORK_REPO>
Branch: <default_branch> (commits on top of upstream)
Upstream: https://github.com/<UPSTREAM>
Sync: git fetch upstream && git merge upstream/<default_branch>
Or use GitHub's "Sync fork" button (web UI)
No automated workflow needed. Use any of these approaches when you want upstream changes:
# CLI: fetch and merge upstream
git fetch upstream
git merge upstream/main --no-edit
git push
# Or use gh CLI
gh repo sync owner/repo
Or use GitHub's built-in "Sync fork" button in the web UI.
If merge conflicts occur: Resolve them manually — your custom patches are on top, so conflicts show exactly where upstream diverged from your edits.
| Step | Command | Purpose |
|---|---|---|
| Fork | gh repo fork OWNER/REPO | Create fork on GitHub |
| Clone | gh repo clone FORK ~/git/REPO | Clone to ~/git/ |
| Upstream | git remote add upstream URL | Track upstream |
| Edit | Work on default branch | Apply custom patches |
| Push | git push origin main | Publish changes |
| Sync | git fetch upstream && git merge upstream/main | Pull upstream changes |
No upstream remote configured
git remote add upstream after cloningVague commit messages
custom:, include upstream URL and reasonForking without confirming
Creating separate branches or sync workflows
Never:
Always:
main or master)custom: and include upstream URL