git remote add <remote> <url>

Add a new named remote pointing to a Git repository URL.

This command is useful for connecting your local repository to one or more remote repositories so you can fetch, pull, and push changes to them by a simple name instead of repeatedly typing long URLs.

This command tells Git to create a new remote entry named <remote> that points to the repository located at <url>, where <remote> is a short alias like origin or upstream and <url> is something like https://github.com/user/repo.git or git@github.com:user/repo.git; it stores this mapping in your local repo’s configuration so later commands like git fetch <remote>, git pull <remote>, and git push <remote> know which server to talk to. The remote subcommand is the part of Git that manages these named connections, add means you’re creating a new one, <remote> is just the label you’ll use on the command line, and <url> is the actual location of the remote repository.

You can combine this with other git remote operations, such as git remote -v to list all configured remotes with their URLs, git remote rename <old> <new> to change a remote’s name, or git remote set-url <remote> <new-url> to change an existing remote’s URL without deleting and re-adding it; to remove a remote entirely, you can use git remote remove <remote> or its shorter equivalent git remote rm <remote>. A common pattern is to first initialize a repo with git init, then use this command to connect it to a hosting service, after which you can run git push -u <remote> <branch> to push your local branch and set up upstream tracking.

Examples:

  • git remote add origin https://github.com/my-user/my-repo.git
  • git remote add upstream https://github.com/original-author/the-repo.git
Related commands

Welcome to GitExamples!

Sign in to gitexamples