在使用git来进行版本控制时,为了得一个项目的拷贝(copy),我们需要知道这个项目仓库的地址(Git URL). Git能在许多协议下使用,所以Git URL可能以ssh://, http(s)://, git://,或是只是以一个用户名(git 会认为这是一个ssh 地址)为前辍. 
有些仓库可以通过不只一种协议来访问,例如,Git本身的源代码你既可以用 git:// 协议来访问:
git clone git://git.kernel.org/pub/scm/git/git.git
也可以通过http 协议来访问:
git clone http://www.kernel.org/pub/scm/git/git.git
git://协议较为快速和有效,但是有时必须使用http协议,比如你公司的防火墙阻止了你的非http访问请求.如果你执行了上面两行命令中的任意一个,你会看到一个新目录: 'git',它包含有所的Git源代码和历史记录.
   在默认情况下,Git会把"Git URL"里最后一级目录名的'.git'的后辍去掉,做为新克隆(clone)项目的目录名: (例如. git clone http://git.kernel.org/linux/kernel/git/torvalds/linux-2.6.git 会建立一个目录叫'linux-2.6')
  另外,如果访问一个Git URL需要用法名和密码,可以在Git URL前加上用户名,并在它们之间加上@符合以表示分割,然后执行git clone命令,git会提示你输入密码。
示例
git clone robin.hu@http://www.kernel.org/pub/scm/git/git.git
这样将以作为robin.hu用户名访问http://www.kernel.org/pub/scm/git/git.git,然后按回车键执行git clone命令,git会提示你输入密码。
另外,我们可以通过-b <name>来指定要克隆的分支名,比如
$ git clone -b master2 ../server .
表示克隆名为master2的这个分支,如果省略-b <name>表示克隆master分支。

GIT URLS

In general, URLs contain
information about the transport protocol, the address of the remote
server, and the path to the repository. Depending on the transport
protocol, some of this information may be absent.
Git natively supports ssh, git, http, https, ftp, ftps, and rsync protocols. The following syntaxes may be used with them:
  • ssh://[user@]host.xz[:port]/path/to/repo.git/
  • git://host.xz[:port]/path/to/repo.git/
  • http[s]://host.xz[:port]/path/to/repo.git/
  • ftp[s]://host.xz[:port]/path/to/repo.git/
  • rsync://host.xz/path/to/repo.git/
An alternative scp-like syntax may also be used with the ssh protocol:
  • [user@]host.xz:path/to/repo.git/
The ssh and git protocols additionally support ~username expansion:
  • ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
  • git://host.xz[:port]/~[user]/path/to/repo.git/
  • [user@]host.xz:/~[user]/path/to/repo.git/
For local repositories, also supported by git natively, the following syntaxes may be used:
    • /path/to/repo.git/
    • Examples

      • Clone from upstream:
        $ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6 $ cd my2.6 $ make
      • Make a local clone that borrows from the current directory, without checking things out:
        $ git clone -l -s -n . ../copy $ cd ../copy $ git show-branch
      • Clone from upstream while borrowing from an existing local directory:
        $ git clone --reference my2.6 \ git://git.kernel.org/pub/scm/.../linux-2.7 \ my2.7 $ cd my2.7
      • Create a bare repository to publish your changes to the public:
        $ git clone --bare -l /home/proj/.git /pub/scm/proj.git
      • Create a repository on the kernel.org machine that borrows from Linus:
        $ git clone --bare -l -s /pub/scm/.../torvalds/linux-2.6.git \ /pub/scm/.../me/subsys-2.6.git

git命令之git clone用法的更多相关文章

  1. 每日一条 Git 命令:git merge remote master

    每日一条 Git 命令:git merge remote master 当远程的分支更新后,需要将自己的代码与远程的分支合并就用以下这个命令合并. git merge remote master 如果 ...

  2. git命令之git remote的用法

    git remote git  remote -v git init git add xxx git commit -m 'xxx' git remote add origin ssh://softw ...

  3. [转]git命令之git remote的用法

    git remote git  remote -v git init git add xxx git commit -m 'xxx' git remote add origin ssh://softw ...

  4. git命令之git rebase 的用法

    rebase 假设你现在基于远程分支"origin",创建一个叫"mywork"的分支. $ git checkout -b mywork origin 现在我 ...

  5. Git 命令及git服务器

    Linux 服务器上安装git yum -y install git git config  --global user.name "name" git config  --glo ...

  6. 第23月第24天 git命令 .git-credentials git rm --cached git stash clear

    在git push的时候,有时候我们会想办法撤销git commit的内容 1.找到之前提交的git commit的id git log 找到想要撤销的id 2.git reset –hard id ...

  7. git命令学习之clone指定分支代码

    今天要拉取一个项目,但是是一个指定分支,本来我以为直接git clone就行,但是发现好像不能,报错: Cloning into 'lecture'...fatal: unable to update ...

  8. Git命令(Git版本:Linux 2.14.3)

    常用 git status 跟踪状态git commit -m "xxx" yyy.cppgit pull git pushgit mergetool --tool=meld 合并 ...

  9. git命令之git tag 给当前分支打标签

    git tag - 标签相关操作 发表于 2011年06月29日 由 机器猫 标签可以针对某一时间点的版本做标记,常用于版本发布. 列出标签 $ git tag # 在控制台打印出当前仓库的所有标签$ ...

随机推荐

  1. js时间戳转换时间、距当前时间

    // 1.时间戳转化成时间格式 function getTime(times) { return new Date(parseInt(times) * 1000).toLocaleString().r ...

  2. OpenStack容器网络项目Kuryr(libnetwork)

    转:https://www.aliyun.com/jiaocheng/518375.html 摘要:容器近几年非常流行,有很多项目都考虑将容器与SDN结合.Kuryr就是其中一个项目.Kuryr项目在 ...

  3. flask-include标签使用标签

      [footer.html] <footer> 这是底部 </footer> [header.html] <style> .nav ul{ overflow: h ...

  4. php urlencode函数 (中文字符转换为十六进制)

    urlencode()函数原理就是首先把中文字符转换为十六进制,然后在每个字符前面加一个标识符%. urldecode()函数与urlencode()函数原理相反,用于解码已编码的 URL 字符串,其 ...

  5. [洛谷U40581]树上统计treecnt

    [洛谷U40581]树上统计treecnt 题目大意: 给定一棵\(n(n\le10^5)\)个点的树. 定义\(Tree[l,r]\)表示为了使得\(l\sim r\)号点两两连通,最少需要选择的边 ...

  6. JavaScript_作用域(2017-03-16)

    这里写的还不够清楚. 建议去看:王福朋 的博客的加深理解. 深入理解javascript原型和闭包(8)——简述[执行上下文]上 深入理解javascript原型和闭包(9)——简述[执行上下文]下 ...

  7. Django拾遗--pagination、sitemap、admin、form

    Django拾遗--pagination.sitemap.admin.form pagination 其实这个分页模块的原理就是根据设定的每页条数来分割queryset.查询结果/每页子项数目=页数 ...

  8. git 分支合并冲突

    准备新的feature1分支,继续我们的新分支开发 [root@node1 git]# git checkout -b feature1 D git/LICENSE.txt Switched to a ...

  9. 奇怪吸引子---Qi

    奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...

  10. zeromq学习笔记1——centos下安装 zeromq-4.1.2

    1.前言 MQ(message queue)是消息队列的简称,可在多个线程.内核和主机盒之间弹性伸缩.ZMQ的明确目标是“成为标准网络协议栈的一部分,之后进入Linux内核”.现在还未看到它们的成功. ...