2017-01-23 129 views
0

的路上,我在我的服務器上創建了命令一個Git倉庫:檢索一個Git倉庫

$ cd /var/www/html 
$ git init 
$ git add . 
$ git commit -m 'inital commit' 

現在,我需要克隆我的本地機器上這個倉庫。我如何檢索git clone的正確路徑?

感謝

回答

2

如果你不使用任何git的服務器,你可以從SSH克隆它:

git clone ssh://[email protected]:sshport/var/www/html/.git 

例如:

git clone ssh://[email protected]:22/var/www/html/.git 
+0

注意,SSH還需要一些配置,這取決於操作系統OP所使用的 – Dunno

+1

以上將無法正常工作,所以需要將git init與--bare在服務器上。 – mhshimul

2

你需要建立一個空庫通過運行帶有--bare選項的git init來初始化沒有工作目錄的存儲庫:

$ cd /srv/git 
$ mkdir project.git 
$ cd project.git 
$ git init --bare 
Initialized empty Git repository in /srv/git/project.git/ 

然後在您的計算機上,

$ cd myproject 
$ git init 
$ git add . 
$ git commit -m 'initial commit' 
$ git remote add origin [email protected]:/srv/git/project.git 
$ git push origin master 

在這一點上,你可以複製下來,並備份一樣容易推的變化:

$ git clone [email protected]:/srv/git/project.git 
$ cd project 
$ vim README 
$ git commit -am 'fix for the README file' 
$ git push origin master 

參考:https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server