---
title: "Deploy from GitHub or GitLab on every push in 2026, with while"
url: https://while.sh/en/guides/keep-github-gitlab/
author: "Aloïs Oddon, co-founder of Nextmap"
updated: 2026-11-19
---

# Keep GitHub or GitLab as your main repository, and deploy on every push (2026)

Your code stays on GitHub or GitLab. A push to the default branch updates production, every merge request opens a preview whose address arrives as a comment, and every commit gets its status.

> **The short version.** Create a token limited to your repository on GitHub or GitLab, then link the repository in the app's settings, or ask your AI to. A push to the default branch updates production, every merge request opens a preview, and every commit gets its status.

## Prerequisites

- An app on while.
- Its repository on GitHub or GitLab, and the right to create an access token there.

## Step 1: Create an access token

On GitHub, create **a fine-grained token limited to this repository** (source 1). Give it Contents read access, and Webhooks, Commit statuses and Pull requests write access.

On GitLab, create **a token with the `api` scope** (source 2). Your account must have the Maintainer role on the project.

## Step 2: Link the repository

In while, open the app's settings, in the Code and budget section, then click Link a repository. Choose GitHub or GitLab, paste the repository and the token. The repository is written `atelier/boutique`, or pasted as you copy it from GitHub or GitLab.

Your AI can also link it, with the `link_git_repo` tool:

> You, to your AI: Link the app to our GitHub repository atelier/boutique.

It links it with the token you give it. With ChatGPT and Codex, the token does not go through the AI: it gives you the link to while's form, where you paste it.

## What happens on every push

A push to the repository's default branch, `main` most often, **updates production**. Another branch does not touch it.

A merge request opens **a preview**, `pr-12` on GitHub or `mr-12` on GitLab, built from its latest commit. Its address arrives as a comment on the request as soon as it answers, and the preview is removed when the request is closed or merged.

**Every commit gets its status** on GitHub or GitLab: building, in production or failed, with the link to the app.

<figure class="illus"><img src="/illustrations/git-forge-statuts-1200.webp" srcset="/illustrations/git-forge-statuts-768.webp 768w, /illustrations/git-forge-statuts-1200.webp 1200w" sizes="(min-width: 48rem) 46rem, 100vw" width="1536" height="1024" loading="lazy" decoding="async" alt="Continuous deployment from GitHub or GitLab to while: the status of each commit, building, in production or failed, the preview address as a comment on the merge request, a release waiting for a person's approval and a fork request authorized by hand" /><figcaption>Every commit has its status, every merge request its preview.</figcaption></figure>

When a release must be approved by a person, the commit status says so, with the link to the request. Once approved, it goes out on its own.

A merge request from a fork is not built on its own. A person on the project who can deploy authorizes each commit in while, and the preview receives none of the project's secrets.

## Unlink the repository

In the app's settings, Unlink removes the webhook on GitHub or GitLab and erases the token from while. A push no longer deploys the app.

> You, to your AI: Unlink the app's GitHub repository.

## The other way: push from GitHub Actions

If you prefer to keep deployment in your CI, your workflow pushes the code to the app's git repository at while, with a token limited to this app.

In while, click Create a token for a CI. Choose the app, the right to deploy and read, and production as the only place it acts. Copy it: it is shown only once.

In GitHub, add it to the repository's secrets as `WHILE_TOKEN`, then add this workflow:

```yaml titre=".github/workflows/while.yml"
name: while
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - run: git push "https://while:${WHILE_TOKEN}@app.while.sh/git/boutique.git" HEAD:main
        env:
          WHILE_TOKEN: ${{ secrets.WHILE_TOKEN }}
```

Replace the address with your app's, given in its settings on the Git repository line. A push to `main` at while updates production. The workflow fetches the whole repository history: git refuses to push a clone without its history to another repository.

## Next steps

- [See every new version before production](/en/guides/preview-environments/)
- [Roll back to the previous version in one second](/en/guides/rollback/)
- [Your app's variables and secrets](/en/guides/environment-variables-secrets/)
- [Each app's git repository](/en/docs/building-blocks/git/)

## Sources

1. [GitHub, Managing your personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens), 2026-11-19
2. [GitLab, Personal access tokens](https://docs.gitlab.com/user/profile/personal_access_tokens/), 2026-11-19

## Questions

### Do I still need to push to while's git repository?

No. Once the repository is linked, a push to GitHub or GitLab is enough.

### What happens to the token?

It is kept in while's vault. It can never be read back, neither in while nor by your AI.

### I link another repository. What happens to the first one?

It is unlinked, and its webhook is removed. Only the new repository deploys the app.

### My GitLab is self-hosted. Does it work?

Yes, like a GitHub Enterprise. Paste the repository's address, and the forge is recognized from it.

### Does a release that needs approval still go out?

It waits. The commit status says so, with the link to the request, and once approved, it goes out on its own.

### What about a merge request from a fork?

It is not built on its own. A person on the project authorizes each commit in while, and the preview receives none of the project's secrets.
