2013-07-26 59 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美元/月。一探究竟。 –

相关问题