GIT远程仓库的使用

查看当前项目有哪些远程仓库

$ git remote 
bixiaopeng@bixiaopengtekiMacBook-Pro wirelessqa$ git remote
origin

查看远程仓库

$ git remote -v 
bixiaopeng@bixiaopengtekiMacBook-Pro wirelessqa$ git remote -v
origin     git@gitlab.***.com:xiaopeng.bxp/wirelessqa.git (fetch)
origin     git@gitlab.***.com:xiaopeng.bxp/wirelessqa.git (push)

查看远程仓库信息

$ git remote -v <remote-name>
bixiaopeng@bixiaopengtekiMacBook-Pro wirelessqa$ git remote show origin
* remote origin
  Fetch URL: git@gitlab.****.com:xiaopeng.bxp/wirelessqa.git
  Push  URL: git@gitlab.***.com:xiaopeng.bxp/wirelessqa.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date) 

添加远程仓库:

$ git remote add [remote-name] [url]
bixiaopeng@bixiaopengtekiMacBook-Pro robotium$ git remote add test git://github.com/paulboone/ticgit.git
bixiaopeng@bixiaopengtekiMacBook-Pro robotium$ git remote -v
origin     https://github.com/RobotiumTech/robotium (fetch)
origin     https://github.com/RobotiumTech/robotium (push)
test     git://github.com/paulboone/ticgit.git (fetch)
test     git://github.com/paulboone/ticgit.git (push)

删除远程仓库:

$ git remote rm [remote-name]
bixiaopeng@bixiaopengtekiMacBook-Pro robotium$ git remote rm test
bixiaopeng@bixiaopengtekiMacBook-Pro robotium$ git remote -v
origin     https://github.com/RobotiumTech/robotium (fetch)
origin     https://github.com/RobotiumTech/robotium (push)

修改远程仓库:

$ git remote set-url --push [remote-name] [newUrl]

重命名远程仓库

$ git remote rename <old-remote-name> <new-remote-name>

从远程仓库抓取数据 :

$git fetch [remote-name]

说明:

  1. 此命令会到远程仓库中拉取所有你本地仓库中还没有的数据。运行完成后,你就可以在本地访问该远程仓库中的所有分支
  2. fetch 命令只是将远端的数据拉到本地仓库,并不自动合并到当前工作分支,只有当你确实准备好了,才能手工合并

拉取远程仓库:

$ git pull [remote-name] [本地分支名]

说明: 一般我们获取代码更新都是用git pull, 目的是从原始克隆的远端仓库中抓取数据后,合并到工作目录中的当前分支

推送远程仓库:

$ git push [remote-name] [本地分支名]

说明: 只有在所克隆的服务器上有写权限,或者同一时刻没有其他人在推数据,这条命令才会如期完成任务。 如果在你推数据前,已经有其他人推送了若干更新,那你的推送操作就会被驳回。你必须先把他们的更新抓取到本地git pull,合并到自己的项目中,然后才可以再次推送。

$git push origin test:master         // 提交本地test分支作为远程的master分支
$git push origin test:test              // 提交本地test分支作为远程的test分支

原文地址:https://www.cnblogs.com/moqiang02/p/4061127.html