Skip to content
LatchkeyLatchkey home

git remote: Usage, Options & Common CI Errors

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

SubcommandWhat 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
-vList 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@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

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.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card