[英]How can I clone from a git repository from 1 machine to another?
我已經從運行macosx的筆記本電腦A上的服務器克隆了一個git存儲庫。 我有一台運行Linux的筆記本電腦B,如何從筆記本電腦A上的git存儲庫克隆?
如何獲取要克隆的網址?
謝謝。
假設筆記本電腦1上有SSH服務器,則遠程服務器將是:
user@host:/path/to/repository
即輸入:
git clone user@laptopA:/path/to/repository
雖然您可以將回購托管在Web服務器上,但可以使事情變得簡單,您可以直接共享文件並直接從目錄克隆(這將是計算機文件路徑-\\ linuxbox \\ gitshare \\ myproject)。
我建議使用“主”裸存儲庫進行克隆,以簡化機器之間的合並(如果需要)。
您需要設置git守護程序或ssh
由於您要從Mac克隆,
第一種方法 -使用輕量級服務器git daemon
Mac:前往Mac上的存儲庫,確保它是裸露的,即,當您運行ls -lrt
,它應該看起來像
drwxr-xr-x 4 fooo admin 136 21 Dec 12:26 refs -rw-r--r-- 1 fooo admin 205 21 Dec 12:26 packed-refs drwxr-xr-x 4 fooo admin 136 21 Dec 12:26 objects drwxr-xr-x 3 fooo admin 102 21 Dec 12:26 info drwxr-xr-x 12 fooo admin 408 21 Dec 12:26 hooks -rw-r--r-- 1 fooo admin 73 21 Dec 12:26 description -rw-r--r-- 1 fooo admin 161 21 Dec 12:26 config drwxr-xr-x 2 fooo admin 68 21 Dec 12:26 branches -rw-r--r-- 1 fooo admin 23 21 Dec 12:26 HEAD
如果不是,則執行步驟2
運行git clone --bare /<Path to your repository>
創建一個空文件git-daemon-export-ok: echo '' > git-daemon-export-ok
跑
git daemon --base-path=`pwd` --verbose --port=9418
Linux:克隆您的git存儲庫:
git clone git://<mac os ip address> <name of folder you want to check out to>
例子-
git clone git://192.168.1.2 javaAddOn
第二種方法 -使用ssh-[稍微難一些]
MAC:在Mac中,轉到系統偏好設置=>遠程登錄
打開終端以創建ssh密鑰:
cd ~ ssh-keygen -t rsa #Press enter for all default values cd .ssh cat id_rsa.pub >> authorized_keys
LINUX:執行與步驟2中相同的步驟,跳過創建authorized_keys的操作
將Mac上的授權密鑰復制到〜/ .ssh /下的Ubuntu中-
scp <macuser>@<macip>:/Users/<macuser>/.ssh/authorized_keys ~/.ssh/
檢查以確保可以從Linux SSH。 ssh <macuser>@<macip>
如果第5步成功,則可以使用git。
git clone <macuser>@<macip>:<Full Path of the repository location
例
git clone pm@192.168.1:/Users/pm/repositories_git/JavaTasks
最后,如果要同時在Mac和Linux中進行開發並同時提交,則必須使用第二種方法,然后推送和拉取更改。 我有完全相同的設置,但是通常我只在Linux中進行開發,然后將更改推送到Mac中。
我想像
git clone file://\\\\192.168.0.33\yourpath
會工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.