Skip to main content

This version of GitHub Enterprise was discontinued on 2022-06-03. No patch releases will be made, even for critical security issues. For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise. For help with the upgrade, contact GitHub Enterprise support.

Managing remote repositories

Learn to work with your local repositories on your computer and remote repositories hosted on GitHub Enterprise Server.

Adding a remote repository

To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at.

The git remote add command takes two arguments:

  • A remote name, for example, origin
  • A remote URL, for example, https://[hostname]/user/repo.git

For example:

$ git remote add origin https://hostname/user/repo.git
# Set a new remote

$ git remote -v
# Verify new remote
> origin  https://hostname/user/repo.git (fetch)
> origin  https://hostname/user/repo.git (push)

For more information on which URL to use, see "About remote repositories."

Troubleshooting: Remote origin already exists

This error means you've tried to add a remote with a name that already exists in your local repository.

$ git remote add origin https://hostname/octocat/Spoon-Knife.git
> fatal: remote origin already exists.

To fix this, you can:

  • Use a different name for the new remote.
  • Rename the existing remote repository before you add the new remote. For more information, see "Renaming a remote repository" below.
  • Delete the existing remote repository before you add the new remote. For more information, see "Removing a remote repository" below.

Changing a remote repository's URL

The git remote set-url command changes an existing remote repository URL.

Tip: For information on the difference between HTTPS and SSH URLs, see "About remote repositories."

The git remote set-url command takes two arguments:

  • An existing remote name. For example, origin or upstream are two common choices.
  • A new URL for the remote. For example:
    • If you're updating to use HTTPS, your URL might look like:
      https://[hostname]/USERNAME/REPOSITORY.git
    • If you're updating to use SSH, your URL might look like:
      git@hostname:USERNAME/REPOSITORY.git

Switching remote URLs from SSH to HTTPS

  1. Open TerminalTerminalGit Bash.