簡體   English   中英

如何使用git將本地存儲庫復制到遠程服務器?

[英]How to copy a local repository to remote server using git?

我正在嘗試使用git在我的遠程服務器中部署我的本地代碼。

所以這就是我在我的本地文件夾mywebsite /中所做的:

git init
git add .
git commit -m "Initial commit"

然后,在我的Web服務器上

mkdir ~/public_html/myrepo.git
cd myrepo.git
git init --bare

然后,在我的本地文件夾mywebsite /:

git remote add remote_mywebsite ssh://user@domain.com:port/~/public_html/myrepo.git
git push remote_mywebsite master

結果如下:

Counting objects: 89, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (74/74), done.
Writing objects: 100% (89/89), 61.94 KiB, done.
Total 89 (delta 2), reused 0 (delta 0)
To ssh://user@domain.com:8943/~/public_html/myrepo.git
 * [new branch]      master -> master

git pull remote_mywebsite

但是當我登錄我的網絡服務器時,在myrepo.git中,我仍然擁有這些文件和文件夾

./
../
branches/
config
description
HEAD
hooks/
info/
objects/
refs/

我沒有檢索我在本地mywebsite文件夾中的文件和文件夾。

我如何在遠程myrepo.git文件夾中檢索我的代碼? 我做錯什么了嗎 ?

非常感謝你的幫助!

您已經創建了一個沒有工作目錄的遠程存儲庫(這是--bare選項的目的)。 接下來需要做的是將遠程存儲庫克隆到您的網站目錄中。 我使用相同的方法; 我有一個〜/ git目錄,其中包含一個或多個裸git存儲庫,然后是一個或多個網站的克隆。 你的步驟可能是:

# locate your bare repository in a 'git' directory
remote$ mkdir ~/git; mkdir ~/git/mywebsite.git; cd ~/git/mywebsite.git; git init --bare

# set this up as your remote
local$ git remote add origin ssh:.../git/mywebsite.git
local$ git push origin ...

# on the remote, clone into your working website
remote$ cd ~/public_html
remote$ git clone ~/git/mywebsite.git mywebsite

使用這種方法,你可以在本地開發,隨心所欲地推送到遠程,然后,當你准備好時, git pull遙控器來實際更新網站。

這將回答你的問題

http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/

在裸存儲庫中,您不需要擁有源代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM