linux clone命令,git clone命令

git clone命令将存储库克隆到新目录中。

简介

git clone [--template=]

[-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]

[-o ] [-b ] [-u ] [--reference ]

[--dissociate] [--separate-git-dir ]

[--depth ] [--[no-]single-branch]

[--recurse-submodules] [--[no-]shallow-submodules]

[--jobs ] [--] []

描述

将存储库克隆到新创建的目录中,为克隆的存储库中的每个分支创建远程跟踪分支(使用git branch -r可见),并从克隆检出的存储库作为当前活动分支的初始分支。

在克隆之后,没有参数的普通git提取将更新所有远程跟踪分支,并且没有参数的git pull将另外将远程主分支合并到当前主分支(如果有的话)。

此默认配置通过在refs/remotes/origin下创建对远程分支头的引用,并通过初始化remote.origin.url和remote.origin.fetch配置变量来实现。

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

$ git clone

比如,克隆jQuery的版本库。

$ git clone http://github.com/jquery/jquery.git

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

$ git clone

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

示例

以下是所支持协议的一些示例 -

$ git clone http[s]://example.com/path/to/repo.git

$ git clone http://git.oschina.net/yiibai/sample.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协议用于需要用户认证的场合。

应用场景示例

从上游克隆下来:

$ git clone git://git.kernel.org/pub/scm/.../linux.git mydir

$ cd mydir

$ make # 执行代码或其它命令

在当前目录中使用克隆,而无需检出:

$ git clone -l -s -n . ../copy

$ cd ../copy

$ git show-branch

从现有本地目录借用从上游克隆:

$ git clone --reference /git/linux.git

git://git.kernel.org/pub/scm/.../linux.git

mydir

$ cd mydir

创建一个裸存储库以将您的更改发布给公众:

$ git clone --bare -l /home/proj/.git /pub/scm/proj.git

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值