git clone能怎么操作指定分支代碼

git clone”能克隆指定分支代碼。“git clone”命令的作用是將存儲庫克隆到新目錄中,為克隆的存儲庫中的每個分支創(chuàng)建遠(yuǎn)程跟蹤分支(使用“git branch -r”可見),并從克隆檢出的存儲庫作為當(dāng)前活動分支的初始分支。

git clone能怎么操作指定分支代碼

本教程操作環(huán)境:Windows7系統(tǒng)、Git2.30.0版、Dell G3電腦。

git?clone是git中常用的命令,其作用是將存儲庫克隆到新目錄中,可以克隆指定分支代碼。

git?clone命令

git?clone命令的作用是將存儲庫克隆到新目錄中,為克隆的存儲庫中的每個分支創(chuàng)建遠(yuǎn)程跟蹤分支(使用git?branch?-r可見),并從克隆檢出的存儲庫作為當(dāng)前活動分支的初始分支。

在克隆之后,沒有參數(shù)的普通git提取將更新所有遠(yuǎn)程跟蹤分支,并且沒有參數(shù)的git?pull將另外將遠(yuǎn)程主分支合并到當(dāng)前主分支(如果有的話)。

此默認(rèn)配置通過在refs/remotes/origin下創(chuàng)建對遠(yuǎn)程分支頭的引用,并通過初始化remote.origin.url和remote.origin.fetch配置變量來實(shí)現(xiàn)。

執(zhí)行遠(yuǎn)程操作的第一步,通常是從遠(yuǎn)程主機(jī)克隆一個版本庫,這時就要用到git?clone命令。

$?git?clone?

比如,克隆jquery的版本庫。

$?git?clone?http://github.com/jquery/jquery.git

該命令會在本地主機(jī)生成一個目錄,與遠(yuǎn)程主機(jī)的版本庫同名。如果要指定不同的目錄名,可以將目錄名作為git?clone命令的第二個參數(shù)。

$?git?clone??

git?clone支持多種協(xié)議,除了HTTP(s)以外,還支持ssh、Git、本地文件協(xié)議等。

在默認(rèn)情況下,Git會把”Git URL”里最后一級目錄名的’.git’的后輟去掉,做為新克隆(clone)項(xiàng)目的目錄名: (例如. git?clone http://git.kernel.org/linux/kernel/git/torvalds/linux-2.6.git 會建立一個目錄叫’linux-2.6′)

$?git?clone?http[s]://example.com/path/to/repo.git $?git?clone?http://git.oschina.net/yiibai/sample.git $?git?clone?ssh://example.com/path/to/repo.git $?git?clone?git://example.com/path/to/repo.git $?git?clone?/opt/git/project.git? $?git?clone?file:///opt/git/project.git $?git?clone?ftp[s]://example.com/path/to/repo.git $?git?clone?rsync://example.com/path/to/repo.git

SSH協(xié)議還有另一種寫法。

$?git?clone?[user@]example.com:path/to/repo.git

通常來說,Git協(xié)議下載速度最快,SSH協(xié)議用于需要用戶認(rèn)證的場合。

應(yīng)用場景示例

從上游克隆下來:

$?git?clone?git://git.kernel.org/pub/scm/.../linux.git?mydir $?cd?mydir $?make?#?執(zhí)行代碼或其它命令

在當(dāng)前目錄中使用克隆,而無需檢出:

$?git?clone?-l?-s?-n?.?../copy $?cd?../copy $?git?show-branch

從現(xiàn)有本地目錄借用從上游克隆:

$?git?clone?--reference?/git/linux.git? ????git://git.kernel.org/pub/scm/.../linux.git? ????mydir $?cd?mydir

創(chuàng)建一個裸存儲庫以將您的更改發(fā)布給公眾:

$?git?clone?--bare?-l?/home/proj/.git?/pub/scm/proj.git

更多編程相關(guān)知識,請?jiān)L問:編程入門!!

以上就是

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊13 分享