`
jgsj
  • 浏览: 957044 次
文章分类
社区版块
存档分类
最新评论

git使用教程二 远程仓库操作

 
阅读更多

列出当前远程库

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

添加远程库

要添加一个新的远程库,需指定一个简单的名字,以便将来引用,格式如下:
git remote add [shortname] [url]
$ 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

从远程库抓取数据

git fetch [remote-name]
此命令会到远程库中拉取所有你本地库中还没有的数据。
fetch的命令只是将远程库的数据拉到本地库,并不自动合并到当前工作分支,需要手工合并。
$ git fetch
$ git fetch pb
如果设置了跟踪分支,可以使用git pull命令自动抓取数据下来,然后将远端分支自动合并到本地仓库中当前分支。

推送数据到远程库

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
	 
注:推送数据需要在远程库有写权限。
如果在你推送前,已经有其他人推送了若干更新,那你的推送操作就会被驳回。必须先把他们的更新抓取到本地,合并到自己的项目中,然后才可以再次推送

查看远程库信息

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

远程库的删除和重命名

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics