Skip to content
LatchkeyLatchkey home

git remote Command: Manage Remotes in CI

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

Key takeaways

  • git remote set-url rewrites origin to a tokenized URL so CI can push.
  • -v reveals the exact fetch and push URLs a job is using.
  • --push sets a push-only URL when fetch and push need different auth.

Frequently asked questions

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.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card