學(xué)習(xí)啦>學(xué)習(xí)電腦>操作系統(tǒng)>Linux教程>

git命令之git clone用法教程

時間: 志藝942 分享

  自上個世紀(jì)九十年代以來,Linux系統(tǒng)得到了快速的發(fā)展,由于Linux繼承了UNIX的以網(wǎng)絡(luò)為核心的設(shè)計思想,采用模塊化的設(shè)計結(jié)構(gòu),使得Linux取得了廣泛的應(yīng)用。接下來是小編為大家收集的git命令之git clone用法教程,希望能幫到大家。

  git命令之git clone用法教程

  在使用git來進行版本控制時,為了得一個項目的拷貝(copy),我們需要知道這個項目倉庫的地址(Git URL). Git能在許多協(xié)議下使用,所以Git URL可能以ssh://, http(s)://, git://,或是只是以一個用戶名(git 會認(rèn)為這是一個ssh 地址)為前輟.

  有些倉庫可以通過不只一種協(xié)議來訪問,例如,Git本身的源代碼你既可以用 git:// 協(xié)議來訪問:

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

  也可以通過http 協(xié)議來訪問:

  git clone http://www.kernel.org/pub/scm/git/git.git

  git://協(xié)議較為快速和有效,但是有時必須使用http協(xié)議,比如你公司的防火墻阻止了你的非http訪問請求.如果你執(zhí)行了上面兩行命令中的任意一個,你會看到一個新目錄: 'git',它包含有所的Git源代碼和歷史記錄.

  在默認(rèn)情況下,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前加上用戶名,并在它們之間加上@符合以表示分割,然后執(zhí)行g(shù)it 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,然后按回車鍵執(zhí)行g(shù)it 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/

  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用法教程”還想看:

1.git每次提交都要輸入密碼怎么辦

2.怎樣在cmd和powershell中使用git命令

3.Ubuntu系統(tǒng)git每次提交都要輸入密碼如何解決

4.CentOS中Git客戶端怎么安裝

2805643