git remote command
git remote The command is used to manage remote repositories in a Git repository.
git remote The command provides functions for viewing, adding, renaming, and deleting remote repositories.
The following are common uses of the git remote command:
git remote: List the remote repositories configured in the current repository.git remote -v: List the remote repositories configured in the current repository and display their URLs.git remote add: Add a new remote repository. Specify a name and URL for the remote repository and add it to the current repository.git remote rename: Rename a configured remote repository.git remote remove: Delete the specified remote repository from the current repository.git remote set-url: Change the URL of the specified remote repository.git remote show: Display detailed information about the specified remote repository, including the URL and tracking branch.
The following lists the uses of viewing, adding, renaming, and deleting remote repositories, modifying remote repository URLs, and viewing remote repository information:
git remote
git remote -v
git remote add origin https://github.com/user/repo.git
git remote rename origin new-origin
git remote remove new-origin
git remote set-url origin https://github.com/user/new-repo.git
git remote show origin
Application Example
In this chapter we will use Github as the remote repository, so before reading this chapter you need to read the related content about Github:Git Remote Repository (Github)。
Display all remote repositories:
git remote -v
git remote -v can view the list of remote repositories configured in the current repository and their URLs.
Below, we first load the remote repository, then view the information:
$
git clone
https:
//
github.com
/
tianqixin
/
runoob-git-test
$
cd
runoob-git-test
$
git remote
-v
origin https:
//
github.com
/
tianqixin
/
runoob-git-test
(
fetch
)
origin https:
//
github.com
/
tianqixin
/
runoob-git-test
(
push
)
origin is an alias for the remote address.
Display information about a remote repository:
git remote show [remote]
For example:
$ git remote show https://github.com/tianqixin/runoob-git-test
* remote https://github.com/tianqixin/runoob-git-test
Fetch URL: https://github.com/tianqixin/runoob-git-test
Push URL: https://github.com/tianqixin/runoob-git-test
HEAD branch: master
Local ref configured for 'git push':
master pushes to master (local out of date)
Add a remote repository:
git remote add
: the name of the remote repository to add. Usually, the name of the remote repository isorigin, but you can also customize a name.: the URL of the remote repository. It can be an HTTPS, SSH, or Git protocol link pointing to a remote Git repository.
The following command adds a remote repository named origin to the current Git repository, with the URL https://github.com/user/repo.git.
git remote add origin https://github.com/user/repo.git
Example usage:
# 提交到 Github
$ git remote add origin git@github.com:tianqixin/runoob-git-test.git
$ git push -u origin master
After adding a remote repository, you can use other Git commands to interact with it, such as pushing local code to the remote repository, pulling code from the remote repository, etc.
Other related commands:
git remote rm name # 删除远程仓库
git remote rename old_name new_name # 修改仓库名
For more information, see:Git Remote Repository (Github)。
Git Basic Operations