Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

git remote command

git remote command

Git Basic OperationsGit Basic Operations


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:

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 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 OperationsGit Basic Operations