远程仓库是指托管在网络上的项目仓库,可能会有好多个,其中有些你只能读,另外有些可以写。同他人协作开发某个项目时,需要管理这些远程仓库,以便推送或拉取数据,分享各自的工作进展。 管理远程仓库的工作,包括添加远程库,移除废弃的远程库,管理各式远程库分支,定义是否跟踪这些分支,等等
命令介绍
1、查看当前有哪些远程仓库
<code>git remote</code>
<code># git remote</code>
origin
在克隆完某个项目后,git默认会以origin这个名字来标识所克隆的远程仓库
2、显示对应的远程仓库地址
<code>git remote -v</code>
<code># git remote -v</code>
origin <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a> (fetch)
origin <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a> (push)
3、添加远程仓库
git remote add
git remote add pb <a href="git://github.com/paulboone/ticgit.git">git://github.com/paulboone/ticgit.git</a>
查看
<code># git remote -v</code>
origin <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a> (fetch)
origin <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a> (push)
pb <a href="git://github.com/paulboone/ticgit.git">git://github.com/paulboone/ticgit.git</a> (fetch)
pb <a href="git://github.com/paulboone/ticgit.git">git://github.com/paulboone/ticgit.git</a> (push)
4、从远程仓库抓取文件
<code>git fetch </code>
这里我们新增了一个pb仓库
<code># git fetch pb</code>
remote: Counting objects: 43, done.
remote: Total 43 (delta 22), reused 22 (delta 22), pack-reused 21
Unpacking objects: 100% (43/43), done.
From <a href="git://github.com/paulboone/ticgit">git://github.com/paulboone/ticgit</a>
* [new branch] master -> pb/master
* [new branch] ticgit -> pb/ticgit
这条命令会到远程仓库拉取本地没有,而远程仓库有的信息到本地,拉取后的内容只是放到本地仓库,并不会自动合并到当前工作分支,需要手动合并分支
5、查看远程仓库信息
<code>git remote show</code>
例如
<code># git remote show origin</code>
* remote origin
Fetch URL: <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a>
Push URL: <a href="git://github.com/schacon/ticgit.git">git://github.com/schacon/ticgit.git</a>
HEAD branch: master
Remote branches:
master tracked
ticgit tracked
Local branch configured for ‘git pull’:
master merges with remote master
Local ref configured for ‘git push’:
master pushes to master (up to date)
6、远程仓库的删除和重命名
<code>git remote rename</code>
例如
<code># git remote rename pb chenfei</code>
删除
<code>git remote rm</code>