Remote Repository


Remote Repository

The GitHub engagement approach to development is based on the commits of publishing from your local area to GitHub for other people to view, fetch, and update

Remote URL is Git's way of saying "the place where your code is stored." That URL may be your repository on GitHub, or another user's fork, or even a completely different server.

You can only push to two types of URL addresses:

  • An HTTPS URL like https://github.com/user/repo.git
  • An SSH URL, like git@github.com:user/repo.git

Git associates a remote URL with a name, and your default remote is usually called the origin.

header How to create Remote Repository

You can use the command “git remote add” to match a remote URL with a name. For example, you can type the following into the command line:

You can use the git remote add command to match a remote URL with a name. For example, you'd type the following in the command line:

git remote add origin

Adding new repository

To add a new remote repository, use the “git remote add” command, in the directory where your repository is stored. Use the command on the terminal.

The git remote add command takes two arguments:

  • A remote name, for example, origin
  • A remote URL, for example, https://github.com/user/repo.git

Example:

$ git remote add origin https://github.com/user/repo.git

# Set a new remote

$ git remote -v

# Verify new remote

> origin https://github.com/user/repo.git (fetch)

> origin https://github.com/user/repo.git (push)

Changing a remote repository's URL

The git “remote set-url”: command changes the existing URL of the remote repository.The 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://github.com/USERNAME/REPOSITORY.git
    • If you're updating to use SSH, your URL might look like: git@github.com:USERNAME/REPOSITORY.git