LinuxCommandLibrary

git-rename-remote

Rename a remote repository connection name

TLDR

Change the upstream remote to origin

$ git rename-remote [upstream] [origin]
copy

SYNOPSIS

git-rename-remote [-f] <old-name> <new-name>

PARAMETERS

-f, --force
    Force rename without confirmation prompt.

<old-name>
    Current name of the remote to rename.

<new-name>
    New name for the remote.

DESCRIPTION

git-rename-remote is a powerful utility from the git-extras project designed to rename a Git remote repository while automatically updating the upstream tracking configuration for all local branches that reference the old remote name.

The standard git remote rename command only changes the remote's name in the repository's configuration but does not update branch tracking refs, which remain stuck pointing to the old remote (e.g., origin/main stays as-is after renaming origin to upstream). This leads to errors like 'no such remote' when pushing or fetching.

git-rename-remote fixes this by:
• Renaming the remote entry.
• Scanning all local branches for upstream refs matching the old remote.
• Updating them to use the new remote name.
• Prompting for confirmation to prevent accidents (skippable with -f).

Ideal for workflows where remotes are frequently renamed, such as switching from origin (fork) to upstream (original repo). It modifies .git/config directly, ensuring seamless integration. After running, commands like git push work without reconfiguration.

This tool enhances Git usability, saving time on manual git branch --set-upstream-to fixes across multiple branches.

CAVEATS

Modifies .git/config irreversibly; backup first. Only updates local branches, not remotes or other repos. Requires git-extras installed; fails if old remote or branches missing.

EXAMPLE

git-rename-remote origin upstream
Renames origin to upstream, updates all origin/* branch refs.

INSTALLATION

Via package: apt install git-extras or brew install git-extras.
From source: git clone https://github.com/git-extras/git-extras.git && cd git-extras && sudo make install.

SOURCE

HISTORY

Part of git-extras since v1.7.0 (January 2013), authored by Linus Cansby. Evolved to handle edge cases like missing branches; widely used in developer workflows for its convenience over manual fixes.

SEE ALSO

git remote rename(1), git branch --set-upstream-to(1), git-extras(1)

Copied to clipboard