這些都是我的步驟和演示:
- 添加一個文本文件到本地倉庫
- 推動這些變化(即新的文件),以兩者的GitHub和現場服務器
以下假設你:
- 已經在GitHub上設置了一個遠程,並且可以在那裏推送更改
- 是在你的本地庫的目錄名爲
'Program_One'
工作這個過程包括8個步驟:
- 檢查,如果你有你的生活的服務器
- SSH訪問您正在安裝的git服務器
- 創建目錄
‘testdir’
在'yoursite.com/testdir'
- 創建一個目錄在那個叫
'.git'
- 目錄在該目錄中創建一個「裸回購」
- 在
'.git/hooks'
創建後接收文件和chmod它的權限
- 作爲遠程
- 推添加直播服務器到實時服務器和GitHub的
打開終端,輸入ssh到你的在線服務器如下:
ssh [email protected] # the password will be your root password
提出您的主機的首選方式,在您的服務器上安裝Git和做
創建目錄,裸露的回購和後收到文件
[[email protected] /home/username/public_html] mkdir testdir
[[email protected] /home/username/public_html] cd testdir
[[email protected] /home/username/public_html/testdir] mkdir .git
[[email protected] /home/username/public_html/testdir] cd .git
[[email protected] /home/username/public_html/testdir/.git] git init --bare
[[email protected] /home/username/public_html/testdir/.git] cd hooks
[[email protected] /home/username/public_html/testdir/.git/hooks] vi post-receive
# press 'i', paste the following 2 lines, replacing with your details
#!/bin/sh
GIT_WORK_TREE=/home/username/public_html/livetest git checkout -f
# press 'esc', type :w, press enter, type shift+zz
[[email protected] /home/username/public_html/testdir/.git/hooks] chmod +x post-receive
[[email protected] /home/username/public_html/testdir/.git/hooks] exit
在終端中,您的本地存儲庫,添加您的現場服務器作爲遠程:
[[email protected] Program_One] # make sure you are in your local repository
[[email protected] Program_One] git remote add my_great_remote [email protected]:/home/username/public_html/livetest/.git
# change ‘my_great_remote’ to the name you want to call your remote, taking note that the github remote is called ‘origin’.
稱爲「my_text_file.txt」的文本文件添加到您的本地倉庫,然後鍵入在終端執行以下操作:
[[email protected] Program_One] # make sure you are in your local repository
[[email protected] Program_One] git add -all
[[email protected] Program_One] git status
[[email protected] Program_One] git commit -m "added text file"
[[email protected] Program_One] git push -u origin master
[[email protected] Program_One] git push -u my_great_remote master
後收到文件,然後將你的本地庫文件複製到「 TESTDIR」目錄讓您在訪問文本文件:
mysite.com/testdir/my_text_file.txt
我更願意使用CI服務器,如詹金斯或類似部署。 – kan
推送到現場服務器,你需要設置你的上游到你的現場服務器 –