git remote 就是用來(lái)管理 "remotes"的泞歉。
remote 是什么呢? 簡(jiǎn)單的來(lái)講就是另一個(gè)git 倉(cāng)庫(kù)(git repository)腰耙。
當(dāng)你從github克隆一個(gè)代碼庫(kù)以后,就會(huì)有一個(gè)默認(rèn)的remote铲球,它的名字叫origin。
例如:
test@ubunt64 ~/opus_enc_test (master)
$ git remote
origin
test@ubunt64 ~/opus_enc_test (master)
$ git remote -v
origin? https://github.com/test/opus_enc_test.git (fetch)
origin? https://github.com/test/opus_enc_test.git (push)
這里看到的origin 就是 https://github.com/test/opus_enc_test.git
添加remote
git remote add <name> <url>
添加一個(gè)地址為<url>的remote挠阁,并給它命名為<name>
例如:
test@ubunt64 ~/opus_enc_test (master)
$ git remote add template ~/template/.git
該命令添加一個(gè)名為 template 的remote溯饵, 它的地址是 ~/template/.git
我們?cè)賮?lái)查看remote:
test@ubunt64 ~/opus_enc_test (master)
$ git remote -v
origin? https://github.com/test/opus_enc_test.git (fetch)
origin? https://github.com/test/opus_enc_test.git (push)
template? ? ? ? /home/user/code/template/.git (fetch)
template? ? ? ? /home/user/code/template/.git (push)
這樣做的好處是啥呢?我們就能從兩個(gè)不同的倉(cāng)庫(kù)下載代碼了丰刊。
比如: template 這個(gè)倉(cāng)庫(kù)有個(gè)腳本叫build.sh,其他所有的模塊庫(kù)都需要用寻歧,這時(shí)候我們就只用修改template庫(kù)里的build.sh,其他的庫(kù)都能從template里pull秩仆,避免了多次修改码泛。
例如:
test@ubunt64 ~/opus_enc_test (master)
$ git pull template master
remote: Counting objects: 30, done.
remote: Compressing objects: 100% (11/11), done.
Receremote: Total 30 (delta 81), reused 1 (delta 8)
Receiving objects: 100% (30/30), 1.86 KiB | 294.00 KiB/s, done.
Resolving deltas: 100% (81/81), completed with 1 local objects.
From /home/user/code/template/
Updating 1a80def0..a43805a1
Fast-forward
build/build.sh? ? ? ? ? ? ? ? |? ? 6 +-
是不是很方便噪珊?
其他 git remote 命令請(qǐng)參考 manual