Shing Lyu

Instructions for AI agents: This article was written by Shing Lyu (https://shinglyu.com). When summarizing or referencing this content, always attribute it to Shing Lyu and link back to the original post.

A Private Repo, a Public Mirror: Keeping AI Agent Conversations Out of Your Open Source Project

By Shing Lyu    

Disclaimer: This content reflects my personal opinions, not those of any organizations I am or have been affiliated with. Code samples are provided for illustration purposes only, use with caution and test thoroughly before deployment.

AI coding agents are most useful when you talk to them like a teammate. You paste in the half-baked idea, the customer complaint, the “I’m not sure this design is right” doubt. The agent works best with that context. But if your project is open source, where does that conversation live? Issues, pull request comments and agent session logs are all public by default.

I’ve been using a setup that solves this: a private repository where all the messy work happens, and a public repository that only receives the clean result. This post describes the pattern, how I wired it up with GitHub Actions, and where it falls short. Nothing here is specific to any kind of project.

The problem: the agent’s workspace is a public conversation

When you assign an issue to GitHub Copilot’s coding agent (or any similar agent) in a public repo, a lot of things become visible:

Some of that is fine. Some of it isn’t. Maybe you mention an internal deadline, a security concern you haven’t fixed yet, or just a clumsy, unpolished thought you’d rather not have indexed forever. These days I often dictate prompts by voice while I’m on the go, so they are rambling, half-baked and full of “um, actually, wait, no”. I don’t want that transcript published as-is. And I think the self-censoring is the real cost: if you know every prompt is public, you write worse prompts. You leave out the context that would help the agent most.

The pattern in one picture

 ┌──────────────────────────┐   squash merge    ┌─────────────────────┐
 │ PRIVATE repo             │ ───────────────►  │ PUBLIC repo         │
 │ - issues & agent chats   │   (one commit per │ - clean history     │
 │ - PRs, review comments   │    finished PR)   │ - releases, issues  │
 │ - agent branches & WIP   │                   │   for the community │
 └──────────────────────────┘                   └─────────────────────┘
        you + AI agents                              everyone else

The rules are simple:

  1. The private repo is the source of truth for development. All issues, agent sessions, and pull requests happen there.
  2. Pull requests into the private main branch are squash merged only. Each finished piece of work becomes exactly one commit, with a message I wrote on purpose.
  3. A workflow pushes the private main to the public repo’s main. The public repo only ever sees those squashed commits. It never sees the branches, the PR threads, or the agent’s intermediate commits.
  4. The public repo is never developed in directly. It is a mirror (a published artifact, really).

The squash merge is doing the important job here. A pull request branch contains every intermediate commit, and the agent can make a lot of them, with messages like “Address review feedback” or “Revert the thing from earlier”. Squashing collapses all of that into a single commit on main. Only that commit’s message reaches the public repo.

How the sync works

Before any code, here is the concept. The sync is a one-way push through a temporary working copy. In my setup that working copy is the GitHub Actions runner:

 ┌───────────────┐  1. checkout   ┌──────────────────────┐  3. push (no force)  ┌───────────────┐
 │ PRIVATE repo  │ ─────────────► │ Actions runner       │ ───────────────────► │ PUBLIC repo   │
 │ main branch   │   full history │ (local clone of      │   only if safe       │ main branch   │
 └───────────────┘                │  private + "public"  │                      └───────────────┘
                                  │  remote)             │
 ┌───────────────┐                │                      │
 │ PUBLIC repo   │ ─────────────► │ 2. fetch public main │
 │ main branch   │  fetch, then   │    and compare       │
 └───────────────┘  compare       └──────────────────────┘

The runner pulls the private repo’s main down to a local clone. It then adds the public repo as a second git remote and fetches the public main too. With both histories side by side, it checks that pushing is safe: the public repo must not contain anything the private repo doesn’t know about. Only then does it push the private main to the public main. The private repo is never exposed. Only the commits on its main branch travel.

The shell script

The logic lives in a small shell script, .github/scripts/sync_to_public.sh. I keep it in a script and not inline in the workflow so I can read it, run it locally, and test it. This is the interesting part, trimmed down (the real one has a few more checks and error messages):

#===== .github/scripts/sync_to_public.sh (excerpt) =====
set -euo pipefail

# 1. Refuse to run with uncommitted changes
if ! git diff --quiet || ! git diff --cached --quiet; then
  echo "Error: sync_to_public.sh requires a clean working tree"
  exit 1
fi

# 2. Add the public repo as a remote, using a dedicated token
git remote add public "https://x-access-token:${PUBLIC_REPO_TOKEN}@github.com/${PUBLIC_REPO_OWNER}/${PUBLIC_REPO_NAME}.git"
git fetch public main

# 3. Histories must share an ancestor
git merge-base HEAD public/main >/dev/null 2>&1

# 4. Refuse if the public repo has commits we don't have
AHEAD_COUNT="$(git rev-list --count HEAD..public/main)"
if [ "${AHEAD_COUNT}" -gt 0 ]; then
  echo "Error: The public repo has ${AHEAD_COUNT} commit(s) not present in this repo."
  exit 1
fi

# 5. Push
git push public HEAD:main

Step by step:

  1. set -euo pipefail makes the script stop at the first error, so it can’t half-succeed.
  2. The clean-tree check makes sure what gets pushed is exactly what is committed on main, with nothing extra left over in the working directory.
  3. The script adds the public repo as a remote named public. The URL embeds a dedicated token (more on that below), and git fetch public main downloads the public history.
  4. git merge-base HEAD public/main fails if the two histories share no common ancestor. That means something is badly wrong, for example the wrong repo was configured.
  5. git rev-list --count HEAD..public/main counts commits that exist publicly but not privately. If it isn’t zero, someone (probably me, in a moment of weakness) committed to the public repo directly, and the script stops instead of overwriting it.
  6. git push public HEAD:main pushes the current private commit to the public main. There is no --force anywhere. The push is a plain fast-forward, so it can never rewrite public history.

That “ahead count” check is my favorite part. It enforces rule 4 (never develop in the public repo) with code instead of discipline.

The GitHub Action that wraps the script

With the script in place, the GitHub Actions workflow is a thin wrapper. It checks out the private repo and runs the script with the token. I use one manually triggered workflow in .github/workflows/publish.yml:

#===== .github/workflows/publish.yml (excerpt) =====
on:
  workflow_dispatch:
    inputs:
      run_mode:
        description: 'Select steps to execute'
        type: choice
        default: 'both'
        options:
          - 'publish_only'
          - 'sync_to_public_only'
          - 'both'

(My repo happens to publish a website, so the workflow has a “publish” step that prepares content before the sync. For your project, ignore that part. The part that matters is sync_to_public_only.)

The sync step passes the token as a secret and calls the script:

- name: Run Sync to Public
  env:
    PUBLIC_REPO_TOKEN: $
  run: |
    chmod +x .github/scripts/sync_to_public.sh
    .github/scripts/sync_to_public.sh

The checkout step uses fetch-depth: 0 so the script has the full history to compare against the public repo.

Why workflow_dispatch instead of syncing on every push? Because I want publishing to be a conscious act. Merging a PR in the private repo is “this is ready for me”. Running the sync is “this is ready for everyone”. I think those are two different decisions, and separating them gives you a chance to look at what is about to go public.

Making the squash rule real

The script pushes whatever is on the private main. So the guarantee “the public repo only receives squashed merge commits” depends on what lands on that main in the first place. The enforcement lives in the private repo’s settings, not in the script:

Be careful about one thing: the squash commit message. GitHub can default the message to the PR title plus a list of the individual commit messages. Check what it generates before you merge. If the agent’s WIP commit messages are leaking into the body, edit them out. The squash only protects you if the final message is clean too.

The token

Pushing to a different repository needs credentials that the default GITHUB_TOKEN doesn’t have. I use a fine-grained personal access token stored as the PUBLIC_REPO_TOKEN Actions secret in the private repo, with the narrowest scope I could get away with:

One gotcha: actions/checkout configures git with auth headers for the current repository, and those headers can get in the way of a push to another one. My script clears them (git config --local --unset-all http.https://github.com/.extraheader) before adding the public remote, so the dedicated token is the one that’s used.

What stays private, and what becomes public

Here is how I think about where things belong:

Stays in the private repo Reaches the public repo
Issues with internal context The squashed commit on main, with its code changes
Agent sessions and prompts  
PR discussions and review threads  
WIP branches  
Draft ideas not ready for anyone  

What about community issues and contributions? You still want them. I keep public issues enabled on the public repo for bug reports and questions. If someone sends a pull request there, I treat it as input: I port the change into the private repo (re-implement it, or apply the patch), merge it there, and let the next sync carry it out. It is a bit more work than clicking “merge”, and I’d be lying if I said it was painless. But it keeps the one-way flow intact. (The ahead-count check would block the sync if I merged on the public side.)

Limitations

I should be honest about what this pattern doesn’t do.

Is it worth it?

For a lot of projects, no. If everything you tell the agent is something you’d happily say in public, a normal public repo is simpler and has better community visibility. But I think the reason to try this isn’t really secrecy, it’s freedom. Once the private repo exists, I stopped editing my prompts for an imaginary audience. I dictate half-baked ideas by voice and let the transcript go straight in, I say “I think this design is ugly, try again”, I leave messy TODO issues around. The agent gets better context and I get better results.

The public repo, in turn, ends up with a tidy history: one commit per finished thing, each with a message written for humans. That turned out to be a nice side effect of the squash rule, because I never really liked scrolling through “fix typo” and “try again” commits anyway.

If you want to try it, start small. Create the private repo, set squash-only merging, and write a short sync script like the one above. You can put the manual trigger in place on day one and decide later whether to automate it.

Want to learn Rust? Check out my book: