Skip to content
Foxipa

Suggest an edit

Tell us what should be corrected, clarified, or improved. Submission will be connected to Foxipa’s contribution service later.

No information is sent anywhere yet. Your suggestion is only prepared in your browser.

Learning

Git Remote Management: Configuring and Inspecting Remotes

Manage local remote configuration with git remote: list, inspect, add, rename, remove, and change remote URLs without confusing configuration changes with fetch, push, or branch operations.

Levels: Intermediate ~35 min read

Intermediate

A remote is local configuration that names another repository

A remote name such as origin is a local name for a configured remote repository. The configuration stores information such as the remote's URL and fetch refspec. Creating or changing that configuration does not create a commit, move HEAD, or modify the remote repository itself.

bash
git remote
git remote -v
git config --get-regexp '^remote\.'

Quick check

What does `git remote` list?

The repository has remotes named origin and upstream configured.`git remote` lists origin and upstream.

Inspect names and URLs before changing configuration

`git remote -v` shows each remote with its fetch and push URLs. `git remote get-url <name>` retrieves the configured URL for a remote. These commands inspect local configuration; they are not fetch operations.

bash
git remote -v
git remote get-url origin
git remote get-url --push origin

Quick check

Which command directly retrieves the configured URL for `origin`?

origin has a configured URL.`git remote get-url origin` prints that URL.

Add a remote without contacting it

`git remote add <name> <URL>` creates local configuration for a new remote. The command does not by itself contact the URL when `--fetch` is not requested, and it does not create a local branch or commit. The normal configuration also establishes a fetch refspec for that remote.

bash
git remote add upstream /srv/git/project.git
git remote -v
git config --get remote.upstream.url
git config --get remote.upstream.fetch

Quick check

What does `git remote add upstream <URL>` change by itself?

The local repository has no remote named upstream.upstream appears in `git remote` and has local URL/fetch configuration.

Change a remote URL without changing its name

`git remote set-url <name> <newurl>` changes the configured fetch URL. With `--push`, it changes the push URL instead. `--add` can add another URL and `--delete` can remove a matching URL, subject to Git's protection against deleting all non-push URLs. These are configuration operations, not network synchronization.

bash
git remote set-url origin ssh://git@example.test/project.git
git remote get-url origin
git remote set-url --add origin https://mirror.example.test/project.git
git remote get-url --all origin

Quick check

What does `git remote set-url origin <URL>` change?

origin points to the old URL.origin's configured URL is changed; no commit or branch movement occurs.

Rename a remote and its local tracking namespace

`git remote rename <old> <new>` changes the local remote name. Git also updates the associated remote-tracking references and configuration keys so the namespace follows the new name. This is a local ref/configuration change; it does not rename a repository on a server.

bash
git remote rename origin upstream
git remote
git config --get remote.upstream.url
git show-ref refs/remotes/upstream/main

Quick check

When `git remote rename origin upstream` succeeds, what is renamed locally?

origin and refs/remotes/origin/main exist locally.upstream and refs/remotes/upstream/main exist instead.

Remove a remote from the local repository

`git remote remove <name>` deletes that remote's local configuration and its associated remote-tracking refs. It does not delete the remote repository or its branches. Removing a remote also does not create a commit or move the current branch.

bash
git remote remove upstream
git remote
git config --get-regexp '^remote\.'
git show-ref refs/remotes/upstream/main

Quick check

What does `git remote remove upstream` remove?

upstream is configured locally and has remote-tracking refs.The local upstream configuration and tracking refs are gone; the external repository is unaffected.

Administrative commands do not perform collaboration workflows

The important boundary is state ownership: `git remote` commands manage local descriptions of other repositories. They are different from `git fetch`, which obtains remote refs and objects; `git pull`, which combines fetching with integration; and `git push`, which updates refs in another repository. Those workflows are owned by later lessons.

Practice what you learned

Use the dedicated Git code-completion exercise for this lesson.

Was this page helpful?

Mark this learning resource complete to track your learning progress.