# git remote Command: Manage Remotes in CI

> git remote manages the set of tracked repositories. Reference for -v and set-url, used in CI to inspect or re-point origin at a tokenized push URL.

Source: https://latchkey.dev/learn/command-reference/git-remote-command-reference  
Updated: 2026-06-26

git remote lists, adds, and edits the named remotes a repository tracks.

CI often clones read-only and then needs to push, so a common pattern is to rewrite the origin URL to include a token. git remote is how you inspect and change those URLs.

## Common flags

- `-v` - list remotes with their fetch and push URLs
- `add <name> <url>` - add a new remote
- `set-url <name> <url>` - change the URL of a remote
- `set-url --push <name> <url>` - set a separate push URL
- `remove <name>` - delete a remote
- `get-url <name>` - print the URL of a remote

## Example

```shell
# Re-point origin at a tokenized URL so CI can push
git remote set-url origin \
  "https://x-access-token:${GITHUB_TOKEN}@github.com/owner/repo.git"
git remote -v
```

## In CI

Rewriting origin with set-url to embed a token is the simplest way to enable pushes after a read-only checkout. Use --push to keep fetch and push URLs separate when the runner pulls anonymously but pushes authenticated.

## 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 remote Command: Manage Remotes in CI?

CI often clones read-only and then needs to push, so a common pattern is to rewrite the origin URL to include a token. git remote is how you inspect and change those URLs.

### In CI?

Rewriting origin with set-url to embed a token is the simplest way to enable pushes after a read-only checkout. Use --push to keep fetch and push URLs separate when the runner pulls anonymously but pushes authenticated.

---

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
