搜索
您的当前位置:首页正文

git命令之git clone用法

来源:二三娱乐

有些仓库可以通过不只一种协议来访问,例如,Git本身的源代码你既可以用 git:// 协议来访问:

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

  另外,如果访问一个Git URL需要用法名和密码,可以在Git URL前加上用户名,并在它们之间加上@符合以表示分割,然后执行git clone命令,git会提示你输入密码。

示例

另外,我们可以通过-b 来指定要克隆的分支名,比如

$ git clone -b master2 ../server .

表示克隆名为master2的这个分支,如果省略-b 表示克隆master分支。

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.

ssh://[user@]host.xz[:port]/path/to/repo.git/

git://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/

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

Top