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 URLsadd <name> <url>- add a new remoteset-url <name> <url>- change the URL of a remoteset-url --push <name> <url>- set a separate push URLremove <name>- delete a remoteget-url <name>- print the URL of a remote
Example
# 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 -vIn 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.
- 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 detachedKey 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.