git remote manages the short names (like origin) that point at remote repository URLs.
Remotes map names to URLs. In CI you often add or rewrite a remote to inject a token-bearing URL.
What it does
git remote lists, adds, renames, and removes the named remotes for a repository, and can change their fetch/push URLs.
Common usage
Terminal
git remote -v # list remotes with URLs
git remote add upstream https://github.com/owner/repo.git
git remote set-url origin https://x-access-token:${TOKEN}@github.com/owner/repo.git
git remote remove upstream
git remote show origin
Options
Subcommand
What it does
add <name> <url>
Add a new remote
set-url <name> <url>
Change a remote URL
remove / rm <name>
Delete a remote
rename <old> <new>
Rename a remote
-v
List remotes with their URLs
Common errors in CI
error: remote origin already exists - use git remote set-url instead of add, or remove it first. fatal: 'X' does not appear to be a git repository means a bad URL or unreachable host; verify the URL and that credentials are embedded or available.
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@v4with:fetch-depth:0 # history, tags, and git describe all need this- run:|git rev-parse --is-shallow-repository # expect falsegit rev-parse --abbrev-ref HEAD # prints HEAD when detached
Frequently asked questions
git remote: Usage, Options & Common CI Errors?
Remotes map names to URLs. In CI you often add or rewrite a remote to inject a token-bearing URL.
What it does?
git remote lists, adds, renames, and removes the named remotes for a repository, and can change their fetch/push URLs.
Common errors in CI?
error: remote origin already exists - use git remote set-url instead of add, or remove it first. fatal: 'X' does not appear to be a git repository means a bad URL or unreachable host; verify the URL and that credentials are embedded or available.