Public Repo Setup
Purpose
Automates the full setup and ongoing management of selective public publishing for private git repos. Uses the orphan branch + worktree pattern so published content shares zero history with the private repo.
Trigger Phrases
- "set up public publishing for {repo}"
- "create a public repo for {repo}"
- "add a safety hook"
- "show my public repos"
- "check public repo status"
- "remove public publishing"
Concepts
- Private repo: The user's existing private git repo with all their content.
- Public repo: A separate public GitHub repo that receives cherry-picked files.
- Orphan branch: A branch with no shared history — the bridge between private and public.
- Worktree: A second checkout directory linked to the same
.gitdatabase, checked out on the orphan branch. - Pre-push hook: A safety script that prevents accidentally pushing private branches to the public remote.
Commands
setup {repo-path}
Full end-to-end setup of public publishing for a private repo.
Steps:
Validate the repo — confirm
{repo-path}is a git repo with at least one commit. If not, stop and explain.Gather configuration — ask the user for:
- Public repo name on GitHub (e.g.,
public-notes). Default:public-{private-repo-name}. - Public repo description (optional).
- Worktree location — where to place the public worktree. Default:
{repo-parent-dir}/{public-repo-name}. - Remote name for the public repo. Default:
public. - Orphan branch name. Default:
public-branch.
- Public repo name on GitHub (e.g.,
Create the public GitHub repo:
gh repo create {username}/{public-repo-name} --public --description "{description}"If
ghis not available or not authenticated, provide the manual GitHub steps instead.Create the orphan branch in the private repo:
cd {repo-path} git switch --orphan {orphan-branch} git commit --allow-empty -m "Init public branch" git switch {original-branch}Add the public remote:
git remote add {remote-name} https://github.com/{username}/{public-repo-name}.gitCreate the worktree:
git worktree add {worktree-path} {orphan-branch}Install the pre-push safety hook — see the
add-hookcommand below. Always install the hook during setup.Push the initial empty commit:
cd {worktree-path} git push {remote-name} {orphan-branch}:main cd {repo-path}Confirm success — summarize what was created:
- Public repo URL
- Worktree path
- Remote name
- How to publish files:
cd {worktree-path} && git checkout {main-branch} -- path/to/file
Offer to save config — ask if the user wants the configuration saved to their global copilot instructions (
~/.copilot/copilot-instructions.md).
add-hook {repo-path}
Install or update the pre-push safety hook on a repo.
Steps:
Locate the git dir — resolve
{repo-path}/.git(or the linked gitdir if it's a worktree).Check for existing hook — if
.git/hooks/pre-pushexists, show it and ask whether to replace or append.Write the hook:
#!/bin/bash remote="$1" if [[ "$remote" != "{remote-name}" ]]; then exit 0 fi echo "⚠️ Pushing to PUBLIC remote" echo "Files in this push:" echo "---" git diff --name-only HEAD~1 HEAD echo "---" read -p "Are you sure? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Push aborted." exit 1 fi PRIVATE_PATTERNS=("secret" "private" "draft" "journal" "internal") FILES=$(git diff --name-only HEAD~1 HEAD) for pattern in "${PRIVATE_PATTERNS[@]}"; do if echo "$FILES" | grep -qi "$pattern"; then echo "🚫 Blocked: found file matching '$pattern'" exit 1 fi doneAsk if the user wants to customize the blocked patterns list.
Confirm the hook is installed.
status {repo-path?}
Show the current state of public publishing for a repo (or all configured repos).
Steps:
If
{repo-path}is provided, inspect that repo. Otherwise, check all repos listed in the user's global copilot instructions under any "Public Publishing" config sections.For each repo, report:
- Private repo path and branch
- Public remote URL
- Worktree path and whether it exists
- Orphan branch name
- Whether the pre-push hook is installed
- Number of files on the public branch vs. private branch
- Last push date to the public remote (from
git log {orphan-branch} -1 --format=%ci)
Flag any issues:
- Worktree missing or corrupt
- Public remote unreachable
- Pre-push hook missing
- Unpushed commits on the orphan branch
teardown {repo-path}
Remove public publishing setup from a repo.
Steps:
Confirm with the user — this is destructive. List what will be removed.
Remove the worktree:
git worktree remove {worktree-path}Delete the orphan branch:
git branch -D {orphan-branch}Remove the public remote:
git remote remove {remote-name}Optionally delete the hook — ask if the user wants to remove the pre-push hook (they may have other hooks in the same file).
Optionally delete the public GitHub repo — ask, and if yes:
gh repo delete {username}/{public-repo-name} --yesRemove config from global copilot instructions if it was saved there.
Confirm what was cleaned up.
Constraints
- Never push a non-orphan branch to the public remote. This is the cardinal rule.
- Always install the pre-push hook during setup. It's not optional.
- Never delete or modify the private repo's main branch — only create/manage the orphan branch.
- Always ask for confirmation before destructive operations (teardown, deleting repos).
- Use
git switch --orphannotgit checkout --orphan— it starts with a clean working tree automatically.