git使用教程二 远程仓库操作
2015-03-09 14:36
323 查看
列出当前远程库
[plain]view plaincopy
1、列出当前所有的远程仓库
$ git remote
origin
korg
test
2、列出远程仓库的url
$ git remote –v
origin git@sprdroid.com/android/build.git
korg git://github.com/android/build.git
test /home/scott/gitrepo/build.git
添加远程库
[plain]view plaincopy
要添加一个新的远程库,需指定一个简单的名字,以便将来引用,格式如下:
git remote add [shortname] copy" target=_blank>
$ git remote add pb git://github.com/scottbuild/bootloader.git
$ git remote –v
origin /home/scott/gitrepo/bootloader.git
pb git://github.com/scottbuild/bootloader.git
从远程库抓取数据
[plain]view plain[url=http://blog.csdn.net/yangwen123/article/details/8664596#]copy
git fetch [remote-name]
此命令会到远程库中拉取所有你本地库中还没有的数据。
fetch的命令只是将远程库的数据拉到本地库,并不自动合并到当前工作分支,需要手工合并。
$ git fetch
$ git fetch pb
如果设置了跟踪分支,可以使用git pull命令自动抓取数据下来,然后将远端分支自动合并到本地仓库中当前分支。
推送数据到远程库
[plain]view plain[url=http://blog.csdn.net/yangwen123/article/details/8664596#]copy
git push [remote] [local.branch]:[remote.branch]
将本地仓库中的local.branch推送到远程仓库remote.branch中。
git push 默认将当前分支推送到远程仓库中。
将本地的test分支推送到origin远程仓库:
$ git push origin test
将本地的scott_test分支推送到origin库的test分支:
$ git push origin scott_test:test
注:推送数据需要在远程库有写权限。
如果在你推送前,已经有其他人推送了若干更新,那你的推送操作就会被驳回。必须先把他们的更新抓取到本地,合并到自己的项目中,然后才可以再次推送
查看远程库信息
[plain]view plaincopy
git remote show [remote-name]
查看某个远程库的详细信息,包括相应的url,处于跟踪状态的远程分支,未同步的远程分支,已删除的远程分支,git push,git pull默认操作分支。
$ git remote show origin
* remote origin
URL:git@sprdroid.com/android/build.git
remote branch merged with ‘git pull’ while on branch master
master
tracked remote branches
test
master
local branch pushed with ‘git push’
master:master
远程库的删除和重命名
[plain]view plaincopy
1、重命名
git remote rename [remote-name] [new-remote-name]
$ git remote rename origin paul
$ git remote
pb
paul
对远程库的重命名,也会使对应的分支名称发生变化。
2、删除
碰到远端服务器迁移,或者克隆镜使用,那么需要移除对应的远程库:
git remote rm [remote-name]
$ git remote rm origin
相关文章推荐
- git使用教程二 远程仓库操作
- Git命令的使用_操作远程仓库——详细教程3
- git使用教程二 远程仓库操作
- git使用教程一 本地仓库操作
- Git基础(3):撤消操作和远程仓库的使用
- git 学习使用总结二(远程仓库操作)
- git 学习使用总结三(远程仓库操作)
- git使用教程一 本地仓库操作
- [iOS]git管理工具Sourcetree使用之提交项目到远程仓库(傻瓜式图文教程)
- Git使用教程之本地仓库的基本操作
- Git的使用教程(七)远程仓库
- Linux操作Git远程仓库与本地仓库同步的教程
- Git简单使用教程(四)-远程仓库
- Linux下安装操作Git远程仓库与本地仓库同步的教程
- Android基础入门教程——1.5.1 Git使用教程之本地仓库的基本操作
- Android基础入门教程——1.5.2 Git之使用GitHub搭建远程仓库
- Git使用教程(四)--远程仓库
- 使用gitbash上传代码到github远程仓库简单教程
- git使用教程一 本地仓库操作
- git 的使用——基本的仓库创建,文件提交,上传操作命令,远程仓库关联