Skip to content
Latchkey

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.

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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →