git remote 命令用于一些對(duì)遠(yuǎn)程倉(cāng)庫(kù)的操作。
git remote 命令可以查看當(dāng)前配置中有哪些遠(yuǎn)程倉(cāng)庫(kù),列出每個(gè)遠(yuǎn)程庫(kù)的簡(jiǎn)短名字。
在克隆完某個(gè)項(xiàng)目后,我們可以看到一個(gè)名為 origin 的遠(yuǎn)程庫(kù),git 默認(rèn)使用這個(gè)名字來(lái)標(biāo)識(shí)克隆的原始倉(cāng)庫(kù)。
我們克隆一個(gè)遠(yuǎn)程倉(cāng)庫(kù)項(xiàng)目,查看一下本地配置中的遠(yuǎn)程倉(cāng)庫(kù)列表:
$ git clone https://github.com/owenliang/go-websocket.git $ cd go-websocket # git remote 不帶參數(shù),列出已經(jīng)存在的遠(yuǎn)程分支 $ git remote origin
其中:origin 是遠(yuǎn)程倉(cāng)庫(kù)的默認(rèn)別名,在很多命令中可以直接代替遠(yuǎn)程倉(cāng)庫(kù)的 Url 使用。
列出每個(gè)遠(yuǎn)程庫(kù)的詳細(xì)信息,在每一個(gè)名字后面列出其遠(yuǎn)程 url。
我們查看一下本地配置中的遠(yuǎn)程倉(cāng)庫(kù)詳細(xì)列表:
$ git remote -v origin https://github.com/owenliang/go-websocket.git (fetch) origin https://github.com/owenliang/go-websocket.git (push)
用于添加本地配置中的一個(gè)遠(yuǎn)程倉(cāng)庫(kù)。
git remote add [shortname] [url]
[shortname] 為遠(yuǎn)程倉(cāng)庫(kù)的別名,比如 origin 是系統(tǒng)默認(rèn)的遠(yuǎn)程倉(cāng)庫(kù)別名。
[url] 為遠(yuǎn)程倉(cāng)庫(kù)的 Url 地址,比如 https://github.com/owenliang/go-websocket.git。
我們添加一個(gè)遠(yuǎn)程倉(cāng)庫(kù),別名為 myproject:
$ git remote add myproject https://github.com/owenliang/go-websocket.git $ git remote -v myproject https://github.com/owenliang/go-websocket.git (fetch) myproject https://github.com/owenliang/go-websocket.git (push) origin https://github.com/owenliang/go-websocket.git (fetch) origin https://github.com/owenliang/go-websocket.git (push)
用于刪除本地配置中的一個(gè)遠(yuǎn)程倉(cāng)庫(kù)。
git remote rm [shortname]
[shortname] 為遠(yuǎn)程倉(cāng)庫(kù)的別名,比如 myproject。
我們刪除本地配置中的一個(gè)遠(yuǎn)程倉(cāng)庫(kù) myproject:
$ git remote rm myproject $ git remote -v origin https://github.com/owenliang/go-websocket.git (fetch) origin https://github.com/owenliang/go-websocket.git (push)
用于重命名本地配置中的一個(gè)遠(yuǎn)程倉(cāng)庫(kù)。
git remote rename [shortname] [new shortname]
[shortname] 為遠(yuǎn)程倉(cāng)庫(kù)的別名。
[new shortname] 為遠(yuǎn)程倉(cāng)庫(kù)的新的別名。
我們將本地配置中的遠(yuǎn)程倉(cāng)庫(kù) myproject 改名為 myproject1:
$ git remote rename myproject myproject1 $ git remote -v myproject1 https://github.com/owenliang/go-websocket.git (fetch) myproject1 https://github.com/owenliang/go-websocket.git (push) origin https://github.com/owenliang/go-websocket.git (fetch) origin https://github.com/owenliang/go-websocket.git (push)