# git town sync: Sync Feature Branches With Trunk

> git town sync pulls and merges trunk into your branch chain. Reference for --all, --stack, the config it needs, and the not-a-repo and config errors in CI.

Source: https://latchkey.dev/learn/command-reference/git-town-sync  
Updated: 2026-06-30

git town sync updates the current branch and its ancestors with the latest trunk and pushes the result.

git-town automates a trunk-based branching workflow. git town sync brings a feature branch (and its parent chain) up to date with the main branch and pushes, in one command.

## What it does

git town sync pulls the latest trunk (the configured main branch), merges or rebases it into the current branch chain according to your sync strategy, and pushes. --all syncs every local branch; --stack syncs the current branch and its ancestors.

## Common usage

```Terminal
# sync the current branch chain with trunk
git town sync
# sync every local branch
git town sync --all
# non-interactive setup of the main branch (needed once)
git config git-town.main-branch main
```

## Options

| Flag / Config | What it does |
| --- | --- |
| --all | Sync all local branches, not just the current chain |
| --stack | Sync the current branch and its ancestors |
| --no-push | Sync locally but do not push |
| --detached | Do not pull updates from trunk (local sync only) |
| git-town.main-branch | Config: which branch is trunk |
| git-town.sync-feature-strategy | Config: merge or rebase |

## In CI

git-town needs its main branch configured (git config git-town.main-branch main) and a full checkout, not a shallow one, so it can find the trunk history. Set the sync strategy explicitly and use --no-push if the job should not write back to the remote.

## Common errors in CI

"this is not a git repository" or "cannot sync: this is not a Git repository" means the command ran outside a checkout. "the required Git Town configuration is missing" or "please provide the main branch" means git-town.main-branch is unset. On a shallow clone git town sync can fail to find trunk; fetch with --unshallow first.

## Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

```.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### git town sync: Sync Feature Branches With Trunk?

git-town automates a trunk-based branching workflow. git town sync brings a feature branch (and its parent chain) up to date with the main branch and pushes, in one command.

### What it does?

git town sync pulls the latest trunk (the configured main branch), merges or rebases it into the current branch chain according to your sync strategy, and pushes. --all syncs every local branch; --stack syncs the current branch and its ancestors.

### In CI?

git-town needs its main branch configured (git config git-town.main-branch main) and a full checkout, not a shallow one, so it can find the trunk history. Set the sync strategy explicitly and use --no-push if the job should not write back to the remote.

### Common errors in CI?

"this is not a git repository" or "cannot sync: this is not a Git repository" means the command ran outside a checkout. "the required Git Town configuration is missing" or "please provide the main branch" means git-town.main-branch is unset. On a shallow clone git town sync can fail to find trunk; fetch with --unshallow first.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
