Articles · Published · By Aron
How to Give an AI Bot Access to Only One GitHub Repo
I'm a content creator and AI strategist, and I use AI bots to build and run my own websites. Every one of those bots needs to push code to GitHub. None of them get access to my whole GitHub account. My rule is: one repo, one fine-grained token, expiring in 30 days. Here's how that works.
1. Create a fine-grained token scoped to one repo
GitHub's fine-grained personal access tokens let you pick exactly which repositories a token can touch. Choose "Only select repositories," pick the one site repo, and give it only the permissions it needs (for example, contents and pull requests). Set the expiration to 30 days. Official docs: Creating a fine-grained personal access token.
The 30-day expiry means that even if I forget about a token, it stops working on its own.
2. Put it in the Secrets box, never in chat
I never paste a token into a chat with the bot. I put it in the bot's Secrets box, and the bot sees it as a private environment variable (in this repo it's called GOULAHAI_GITHUB_TOKEN). The bot's rules:
- Never print the token, log it, or put it in a file.
- Never commit it to the repo.
- To check it exists, run
test -n "$GOULAHAI_GITHUB_TOKEN" && echo set, which only says "set."
3. Let git read the token through a credential helper
Instead of putting the token in the remote URL (where it would be saved in .git/config), git asks a small helper for credentials. The helper reads the environment variable only when it's needed:
git config credential.helper \
'!f(){ echo username=x-access-token; echo "password=$GOULAHAI_GITHUB_TOKEN"; };f' The remote stays a plain https://github.com/OWNER/REPO.git URL. Git docs: gitcredentials.
4. Don't run gh auth login
gh auth login saves a login on the machine. Instead, pass the token for a single command (GH_TOKEN=$GOULAHAI_GITHUB_TOKEN gh ...) or call the GitHub REST API with it in a header. Official docs: gh environment variables.
5. Commit as your own GitHub account
This one bit me. Netlify blocked my bot's first builds with "unrecognized Git contributor." The fix was to have the bot commit as my GitHub account (my username and GitHub no-reply email) and link my GitHub account in Netlify's Git contributor settings. GitHub docs: Setting your commit email address. Netlify docs: Roles and permissions (Git Contributors).
Why bother
If something goes wrong, the damage is limited to one repo, and I can revoke that one token on GitHub without touching anything else. And since the bot can only open pull requests I review, mistakes get caught before they go live. That's how I caught the time my bot skipped adding sources I'd asked for.
