2013-07-26 61 views
4

我是新來的git和GitHub上卻設置了本地存儲庫更新GitHub的倉庫時,I型:如何從本地存儲庫推送到GitHub和Live服務器?

[[email protected] Program] git add . 
[[email protected] Program] git status 
[[email protected] Program] git commit -m "a message" 
[[email protected] Program] git push -u origin master 

我希望能夠做的下一件事是讓這個當我進行更改並推送它們,這些也反映在實況網站上的目錄中。

我在現場服務器上安裝了git,並在那裏建立了一個名爲'testdir'的目錄。

我很想在此目錄下鍵入'git init',但在網上也看到'git init --bare'的引用並且有點困惑。

如果任何人都可以提供一個一步一步的命令列表,以使我能夠將本地存儲庫中所做的更改推送到GitHub和活動服務器,我將不勝感激。

+0

我更願意使用CI服務器,如詹金斯或類似部署。 – kan

+0

推送到現場服務器,你需要設置你的上游到你的現場服務器 –

回答

7

這些都是我的步驟和演示:

  • 添加一個文本文件到本地倉庫
  • 推動這些變化(即新的文件),以兩者的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 
2

您需要在git配置中設置兩個遠程控制檯,一個用於github(這可能是您的「起源」),另一個用於您的其他服務器。像往常一樣推送到github,然後用git push yourserver推送到您的其他服務器。

如果我正確理解了你,你希望推送的更改發佈到某處(不管這是否是一個好主意,我不會辯論) - 這可以通過添加一個「hook」腳本來完成每次推送都已經到服務器上的git存儲庫。掛鉤可以例如將一些文件複製到您的www /目錄。

有關將遙控器(github上和你的服務器)的信息,請參閱man git-remote 有關添加掛鉤信息,請參閱man githooks - 我想,收到後鉤子會適合你以及在這裏。

0

還有另一種方法解決這個問題 - 而不是使用自定義腳本使用託管服務,從您的GitHub庫部署通過FTP/SFTP服務器。其中一項服務是dploy.io

基本上點幾下您可以連結GitHub庫,以dploy.io並輸入您的服務器的詳細信息後,你可以通過UI每次推送或手動自動部署。您還可以通過SFTP運行部署後的shell命令並觸發Web掛鉤。還有一種方法可以預覽部署並在實時運行時觀察它。您還可以獲得廣泛的目標服務列表,如S3,Heroku,DreamObjects和Elastic Beanstalk。

聲明:我是一名開發者。

+0

更新:dploy.io現在是永久免費的1私人回購和支付計劃開始15美元/月。一探究竟。 –

相關問題