Git远程仓库操作

转自文章《git使用教程二 远程仓库操作》https://blog.csdn.net/yangwen123/article/details/8664596

列出当前远程库

[plain]  view plain  copy
  1. 1、列出当前所有的远程仓库  
  2.     $ git remote  
  3.        origin  
  4.        korg  
  5.        test  
  6. 2、列出远程仓库的url  
  7.     $ git remote –v  
  8.        origin [email protected]/android/build.git  
  9.        korg git://github.com/android/build.git  
  10.        test /home/scott/gitrepo/build.git  

添加远程库

[plain]  view plain  copy
  1. 要添加一个新的远程库,需指定一个简单的名字,以便将来引用,格式如下:  
  2. git remote add [shortname] [url]  
  3. $ git remote add pb git://github.com/scottbuild/bootloader.git  
  4. $ git remote –v  
  5.     origin /home/scott/gitrepo/bootloader.git  
  6.     pb git://github.com/scottbuild/bootloader.git  

从远程库抓取数据

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

推送数据到远程库

[plain]  view plain  copy
  1. git push [remote] [local.branch]:[remote.branch]  
  2. 将本地仓库中的local.branch推送到远程仓库remote.branch中。  
  3. git push 默认将当前分支推送到远程仓库中。  
  4.   
  5. 将本地的test分支推送到origin远程仓库:  
  6.    $ git push origin test  
  7. 将本地的scott_test分支推送到origin库的test分支:  
  8.    $ git push origin scott_test:test  
  9.        
  10. 注:推送数据需要在远程库有写权限。  
  11. 如果在你推送前,已经有其他人推送了若干更新,那你的推送操作就会被驳回。必须先把他们的更新抓取到本地,合并到自己的项目中,然后才可以再次推送  

查看远程库信息

[plain]  view plain  copy
  1. git remote show  [remote-name]  
  2. 查看某个远程库的详细信息,包括相应的url,处于跟踪状态的远程分支,未同步的远程分支,已删除的远程分支,git push,git pull默认操作分支。  
  3. $ git remote show origin  
  4.    * remote origin  
  5.    URL:[email protected]/android/build.git  
  6.    remote branch merged with ‘git pull’ while on branch master  
  7.     master  
  8.     tracked remote branches  
  9.     test  
  10.     master  
  11.      local branch pushed with ‘git push’  
  12.     master:master  

远程库的删除和重命名

[plain]  view plain  copy
  1. 1、重命名  
  2.     git remote rename [remote-name] [new-remote-name]  
  3.     $ git remote rename origin paul  
  4.     $ git remote  
  5.         pb  
  6.         paul  
  7.     对远程库的重命名,也会使对应的分支名称发生变化。  
  8. 2、删除  
  9.     碰到远端服务器迁移,或者克隆镜使用,那么需要移除对应的远程库:  
  10.     git remote rm [remote-name]  
  11.     $ git remote rm origin  


猜你喜欢

转载自blog.csdn.net/chenjinlong126/article/details/80211549