Connect OpenClaw to GitHub
Learn how to give your OpenClaw AI agent full access to push, commit, and manage your GitHub repositories — explained in plain English, from scratch.
Table of Contents
- 01.What You'll Need
- 02.Step 1: Create a GitHub Personal Access Token
- 03.Step 2: Create a GitHub Repository
- 04.Step 3: Add Your Token to Your VPS
- 05.Step 4: Give OpenClaw Your Repository Details
- 06.Step 5: Fix Git Authentication (If a Push Fails)
- 07.Step 6: Verify Everything Is Working
- 08.Troubleshooting
- 09.Summary
What You'll Need
- ▸A GitHub account — free at github.com
- ▸A VPS (Virtual Private Server) with OpenClaw already installed and running
- ▸Access to your VPS terminal via SSH (the black command-line window)
- ▸About 15 minutes of focused time
Create a GitHub Personal Access Token
GitHub no longer allows you to use your account password to push code from scripts or bots. Instead, it uses a Personal Access Token (PAT) — think of it like a special password created just for your OpenClaw bot. You generate it once, give it to OpenClaw, and it handles everything from there.
💡 Quick Shortcut
Go directly to github.com/settings/tokens while logged in to skip to the token page instantly.
- Log into github.com and click your profile picture in the top-right corner
- Click Settings from the dropdown menu
⚠️ Common Mistake
You want your account Settings — not the Settings tab inside a repository. Always click your avatar first.
- Scroll all the way to the bottom of the left sidebar and click Developer settings
- Click Personal access tokens → Tokens (classic)
- Click Generate new token → Generate new token (classic)
- Fill in the form:
- Scroll down and click Generate token
- Copy your token immediately — GitHub shows it only once. Paste it into a text file or notes app for now.
⚠️ Don't Close That Page Yet!
Once you navigate away from GitHub, the token disappears forever. If you lose it, you'll need to generate a new one.
Create a GitHub Repository
A repository (or "repo") is like a folder on GitHub where your files live. OpenClaw needs a repo to push its files into. If you already have one set up, skip ahead to Step 3.
- Go to github.com/new
- Give your repo a clear name — for example:
openclaw-workspace - Choose Public or Private — either works fine
- Click Create repository
- Copy your repository URL — it will look like this:
https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
📋 Save This URL
You'll need to provide this URL to OpenClaw when it asks where to push files. Copy it now.
Add Your Token to Your VPS
Now SSH into your VPS and run the command below. This stores your token as an environment variable — which is like leaving a sticky note in your terminal's memory. Any app running in the same session, including OpenClaw, can read it without you having to type it every time.
Replace your_token_here with the token you copied from GitHub:
export GITHUB_TOKEN=your_token_here
The export command only lasts as long as your terminal session is open. If you reboot your server or close your SSH window, it disappears. To make it permanent, run these two commands instead:
echo 'export GITHUB_TOKEN=your_token_here' >> ~/.bashrc
source ~/.bashrc
What Does This Actually Do?
💡 Using Zsh?
If your VPS uses Zsh instead of Bash, replace ~/.bashrc with ~/.zshrc in the commands above.
Give OpenClaw Your Repository Details
When OpenClaw asks where to push your files, provide these three pieces of information:
🔗 Always Use the HTTPS URL
Make sure your repo URL starts with https://github.com/ — not git@github.com:. The SSH format won't work with token authentication.
Fix Git Authentication (If a Push Fails)
Sometimes you'll see this error even after setting your token:
fatal: could not read Username for 'https://github.com'
This happens because your token is stored in your shell environment, but git runs in its own separate process and can't see it. The fix is simple — you write the token into a dedicated git credentials file that git knows how to read.
Run these three commands in your terminal:
git config --global credential.helper store
printf "https://x-access-token:%s@github.com\n" "$GITHUB_TOKEN" > ~/.git-credentials
chmod 600 ~/.git-credentials
Line-by-Line Breakdown
After running these commands, git will silently use your token for all future GitHub operations. No more prompts, no more errors.
Verify Everything Is Working
Run this command to confirm that git can now authenticate with GitHub. Replace the placeholders with your actual username and repo name:
git ls-remote https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
If it works: You'll see a list of branch names and commit hashes — that means GitHub accepted your credentials and OpenClaw is ready to go.
If it fails: Double-check that your token was copied correctly and that you selected the repo scope when creating it. Then jump to the Troubleshooting section below.
Common Problems & Fixes
Authentication is still failing even after setting the token
Run echo $GITHUB_TOKEN — if it prints nothing, the variable wasn't saved. Make sure you ran source ~/.bashrc after adding it. Also check that the token hasn't expired on GitHub under Settings → Developer settings → Tokens.
My token expired — what do I do?
Go to github.com/settings/tokens, click your old token, and click Regenerate token. Then repeat Steps 3 and 5 with the new token value. The old one stops working as soon as it expires.
My push is being rejected even though auth works
Check that your branch name matches exactly — GitHub creates main by default, but older repos may use master. Also make sure your token has the full repo scope, not just public_repo.
I'm getting "Repository not found" errors
Make sure you're using the HTTPS URL format: https://github.com/username/repo.git — not the SSH format that starts with git@github.com:. Token authentication only works over HTTPS.
🎉 You're All Set — Here's What You Did
OpenClaw can now clone, commit, and push to your GitHub repository automatically — no manual input required on every run.