Git12

# 下载远程仓库的所有变动
$ git fetch [remote]

# 显示所有远程仓库
$ git remote -v

# 显示某个远程仓库的信息
$ git remote show [remote]

# 增加一个新的远程仓库,并命名
$ git remote add [shortname] [url]

# 取回远程仓库的变化,并与本地分支合并
$ git pull [remote] [branch]

# 上传本地指定分支到远程仓库
$ git push [remote] [branch]

# 强行推送当前分支到远程仓库,即使有冲突
$ git push [remote] --force

# 推送所有分支到远程仓库
$ git push [remote] --all

#简单查看远程---所有仓库
git remote  (只能查看远程仓库的名字)
#查看单个仓库 git remote show [remote-branch-name] #新建远程仓库 git remote add [branchname] [url] #修改远程仓库 git remote rename [oldname] [newname] #删除远程仓库 git remote rm [remote-name] #获取远程仓库数据 git fetch [remote-name] (获取仓库所有更新,但不自动合并当前分支) git pull (获取仓库所有更新,并自动合并到当前分支) #上传数据,如git push origin master git push [remote-name] [branch]
复制代码

5.3.2、git clone 克隆

远程操作的第一步,通常是从远程主机克隆一个版本库,这时就要用到git clone命令。

$ git clone <版本库的网址>

比如,克隆一个上课示例的版本库。

$ git clone https://github.com/zhangguo5/AngularJS04_BookStore.git

该命令会在本地主机生成一个目录,与远程主机的版本库同名。如果要指定不同的目录名,可以将目录名作为git clone命令的第二个参数。

$ git clone <版本库的网址> <本地目录名>

git clone支持多种协议,除了HTTP(s)以外,还支持SSH、Git、本地文件协议等,下面是一些例子。

复制代码
$ git clone http[s]://example.com/path/to/repo.git/
$ git clone ssh://example.com/path/to/repo.git/
$ git clone git://example.com/path/to/repo.git/
$ git clone /opt/git/project.git 
$ git clone file:///opt/git/project.git
$ git clone ftp[s]://example.com/path/to/repo.git/
$ git clone rsync://example.com/path/to/repo.git/
复制代码

SSH协议还有另一种写法。

$ git clone [user@]example.com:path/to/repo.git/

通常来说,Git协议下载速度最快,SSH协议用于需要用户认证的场合。各种协议优劣的详细讨论请参考 官方文档

示例:

结果:

5.3.3、git remote

为了便于管理,Git要求每个远程主机都必须指定一个主机名。git remote命令就用于管理主机名。

不带选项的时候,git remote命令列出所有远程主机。

$ git remote

 

使用-v选项,可以参看远程主机的网址。

$ git remote -v

 

上面命令表示,当前只有一台远程主机,叫做origin,以及它的网址。

克隆版本库的时候,所使用的远程主机自动被Git命名为origin。如果想用其他的主机名,需要用git clone命令的-o选项指定。

$ git clone -o WeUI https://github.com/Tencent/weui.git
$ git remote

 

上面命令表示,克隆的时候,指定远程主机叫做WeUI。

git remote show命令加上主机名,可以查看该主机的详细信息。

$ git remote show <主机名>

 

git remote add命令用于添加远程主机。

$ git remote add <主机名> <网址>

 

git remote rm命令用于删除远程主机。

$ git remote rm <主机名>

 

git remote rename命令用于远程主机的改名。

$ git remote rename <原主机名> <新主机名>

 

5.3.4、git fetch

一旦远程主机的版本库有了更新(Git术语叫做commit),需要将这些更新取回本地,这时就要用到git fetch命令。

$ git fetch <远程主机名>

 

上面命令将某个远程主机的更新,全部取回本地。

git fetch命令通常用来查看其他人的进程,因为它取回的代码对你本地的开发代码没有影响。

默认情况下,git fetch取回所有分支(branch)的更新。如果只想取回特定分支的更新,可以指定分支名。

$ git fetch <远程主机名> <分支名>

 

原文地址:https://www.cnblogs.com/huaobin/p/14910293.html