git命令之git clone用法教程
自上個(gè)世紀(jì)九十年代以來(lái),Linux系統(tǒng)得到了快速的發(fā)展,由于Linux繼承了UNIX的以網(wǎng)絡(luò)為核心的設(shè)計(jì)思想,采用模塊化的設(shè)計(jì)結(jié)構(gòu),使得Linux取得了廣泛的應(yīng)用。接下來(lái)是小編為大家收集的git命令之git clone用法教程,希望能幫到大家。
git命令之git clone用法教程
在使用git來(lái)進(jìn)行版本控制時(shí),為了得一個(gè)項(xiàng)目的拷貝(copy),我們需要知道這個(gè)項(xiàng)目倉(cāng)庫(kù)的地址(Git URL). Git能在許多協(xié)議下使用,所以Git URL可能以ssh://, http(s)://, git://,或是只是以一個(gè)用戶名(git 會(huì)認(rèn)為這是一個(gè)ssh 地址)為前輟.
有些倉(cāng)庫(kù)可以通過(guò)不只一種協(xié)議來(lái)訪問(wèn),例如,Git本身的源代碼你既可以用 git:// 協(xié)議來(lái)訪問(wèn):
git clone git://git.kernel.org/pub/scm/git/git.git
也可以通過(guò)http 協(xié)議來(lái)訪問(wèn):
git clone http://www.kernel.org/pub/scm/git/git.git
git://協(xié)議較為快速和有效,但是有時(shí)必須使用http協(xié)議,比如你公司的防火墻阻止了你的非http訪問(wèn)請(qǐng)求.如果你執(zhí)行了上面兩行命令中的任意一個(gè),你會(huì)看到一個(gè)新目錄: 'git',它包含有所的Git源代碼和歷史記錄.
在默認(rèn)情況下,Git會(huì)把"Git URL"里最后一級(jí)目錄名的'.git'的后輟去掉,做為新克隆(clone)項(xiàng)目的目錄名: (例如. git clone http://git.kernel.org/linux/kernel/git/torvalds/linux-2.6.git 會(huì)建立一個(gè)目錄叫'linux-2.6')
另外,如果訪問(wèn)一個(gè)Git URL需要用法名和密碼,可以在Git URL前加上用戶名,并在它們之間加上@符合以表示分割,然后執(zhí)行g(shù)it clone命令,git會(huì)提示你輸入密碼。
示例
git clone robin.hu@http://www.kernel.org/pub/scm/git/git.git
這樣將以作為robin.hu用戶名訪問(wèn)http://www.kernel.org/pub/scm/git/git.git,然后按回車鍵執(zhí)行g(shù)it clone命令,git會(huì)提示你輸入密碼。
另外,我們可以通過(guò)-b <name>來(lái)指定要克隆的分支名,比如
$ git clone -b master2 ../server .
表示克隆名為master2的這個(gè)分支,如果省略-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/
file:///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用法教程”還想看: