这些都是我的步骤和演示:
- 添加一个文本文件到本地仓库
- 推动这些变化(即新的文件),以两者的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
推送到现场服务器,你需要设置你的上游到你的现场服务器 –