git命令之git clone用法
发布日期:2021-09-16 12:19:59
浏览次数:7
分类:技术文章
本文共 2724 字,大约阅读时间需要 9 分钟。
转:http://blog.csdn.net/wangjia55/article/details/8818845
在使用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
-
-
转载地址:https://blog.csdn.net/wxwzy738/article/details/43952555 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2024年04月06日 10时02分54秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Android软键盘(1)---输入法界面管理(打开/关闭/状态获取)
2019-04-27
Android动态设置view的高度宽度
2019-04-27
css3 属性 text-overflow 实现截取多余文字内容 以省略号来代替多余内容
2019-04-27
vue 事件总线EventBus的概念、使用以及注意点
2019-04-27
JavaScript 用七种方式教你判断一个变量是否为数组类型
2019-04-27
细讲前端设置cookie, 储存用户登录信息
2019-04-27
Web前端安全策略之CSRF的攻击与防御
2019-04-27
斯坦福CS236-深度生成模型2019-全套课程资料分享
2019-04-27
知识图谱(KG)存储、可视化、公开数据集、图计算、图编程工具分享
2019-04-27
伯克利-《神经技术导论2020(带字幕)》
2019-04-27
机器学习经典书籍-《贝叶斯推理与机器学习》
2019-04-27
欧洲计算机视觉国际会议ECCR20最新论文整理分享
2019-04-27
20年6月最新-《深度神经网络的高效处理技术综述》
2019-04-27
BiliBili 100+国际名校免费公开课整理分享
2019-04-27
清华大学计算机学科推荐学术会议和期刊列表
2019-04-27
【组队学习】【24期】Docker教程
2019-04-27
Datawhale组队学习周报(第010周)
2019-04-27
【直播】杨毅远:集成学习答疑直播之六 -- 幸福感预测案例实战
2019-04-27
如何使用Python的进度条?
2019-04-27