git remote
命令管理一組跟蹤的存儲庫。
要參與任何一個 Git 專案的協作,必須要瞭解該如何管理遠程倉庫。遠程倉庫是指託管在網路上的專案倉庫,可能會有好多個,其中有些你只能讀,另外有些可以寫。同他人協作開發某 個專案時,需要管理這些遠程倉庫,以便推送或拉取數據,分享各自的工作進展。管理遠程倉庫的工作,包括添加遠程庫,移除廢棄的遠程庫,管理各式遠程庫分支,定義是否跟蹤這些分支等等。
使用語法
git remote [-v | --verbose]
git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
git remote rename <old> <new>
git remote remove <name>
git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
git remote set-branches [--add] <name> <branch>…
git remote get-url [--push] [--all] <name>
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add [--push] <name> <newurl>
git remote set-url --delete [--push] <name> <url>
git remote [-v | --verbose] show [-n] <name>…
git remote prune [-n | --dry-run] <name>…
git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)…]
描述
git remote
命令管理一組跟蹤的存儲庫。
示例
以下是一些示例 -
1.查看當前的遠程庫
要查看當前配置有哪些遠程倉庫,可以用 git remote
命令,它會列出每個遠程庫的簡短名字.在克隆完某個專案後,至少可以看到一個名為 origin
的遠程庫, git 默認使用這個名字來標識你所克隆的原始倉庫:
$ git clone http://git.oschina.net/zaixian/sample.git
$ cd sample
(1)git remote
不帶參數,列出已經存在的遠程分支
$ git remote
origin
2)git remote -v | --verbose
列出詳細資訊,在每一個名字後面列出其遠程url
此時, -v
選項(譯注:此為 –verbose
的簡寫,取首字母),顯示對應的克隆地址:
$ git remote -v
origin http://git.oschina.net/zaixian/sample.git (fetch)
origin http://git.oschina.net/zaixian/sample.git (push)
Administrator@MY-PC /D/worksp/sample (master)
$ git remote --verbose
origin http://git.oschina.net/zaixian/sample.git (fetch)
origin http://git.oschina.net/zaixian/sample.git (push)
2.添加一個新的遠程,抓取,並從它檢出一個分支 -
$ git remote
origin
$ git branch -r
origin/HEAD -> origin/master
origin/master
$ git remote add staging git://git.kernel.org/.../gregkh/staging.git
$ git remote
origin
staging
$ git fetch staging
...
From git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
* [new branch] master -> staging/master
* [new branch] staging-linus -> staging/staging-linus
* [new branch] staging-next -> staging/staging-next
$ git branch -r
origin/HEAD -> origin/master
origin/master
staging/master
staging/staging-linus
staging/staging-next
$ git checkout -b staging staging/master
...
3.添加遠程倉庫
要添加一個新的遠程倉庫,可以指定一個簡單的名字,以便將來引用,運行 git remote add [shortname] [url]
:
$ git remote
origin
$ git remote add pb http://git.oschina.net/zaixian/sample.git
$ git remote -v origin http://git.oschina.net/zaixian/sample.git
pb http://git.oschina.net/zaixian/sample2.git 現在可以用字串 pb 指代對應的倉庫地址了.比如說,要抓取所有 Paul 有的,但本地倉庫沒有的資訊,可以運行 git fetch pb:
$ git fetch pb
remote: Counting objects: 58, done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 44 (delta 24), reused 1 (delta 0)
Unpacking objects: 100% (44/44), done.
From http://git.oschina.net/zaixian/sample2.git
* [new branch] master -> pb/master
* [new branch] ticgit -> pb/ticgit
4.模仿 git clone,但只跟蹤選定的分支
$ mkdir project.git
$ cd project.git
$ git init
$ git remote add -f -t master -m master origin git://example.com/git.git/
$ git merge origin
上一篇:
git push命令
下一篇:
git submodule命令