如何从本地存储库推送到GitHub和实时服务器?

use*_*287 5 git github

我是git和GitHub的新手但是我设置了一个本地存储库,在我输入时更新GitHub存储库:

[username@yourhostname Program] git add .
[username@yourhostname Program] git status
[username@yourhostname Program] git commit -m "a message"
[username@yourhostname Program] git push -u origin master
Run Code Online (Sandbox Code Playgroud)

我希望能够做的下一件事是,当我进行更改并推送它们时,这些也会反映在实际站点上的目录中.

我在实时服务器上安装了git并设置了一个名为的目录'testdir'.

我很想'git init'在这个目录中输入,但我也在网上看到引用'git init --bare'并且有点困惑.

我很感激,如果有人能提供一步一步的命令列表,使我能够将本地存储库中的更改推送到GitHub和实时服务器.

use*_*287 8

这些是我的步骤并证明:

  • 将文本文件添加到本地存储库
  • 将这些更改(即新文件)推送到GitHub和实时服务器

以下假定您:

  • 已经在GitHub上设置了一个遥控器,可以推动那里的变化
  • 正在本地存储库中的目录中工作 'Program_One'

这个过程包括8个步骤:

  • 检查您是否具有对实时服务器的ssh访问权限
  • 在您的实时服务器上安装git
  • 创建目录‘testdir’'yoursite.com/testdir'
  • 在该目录中创建一个名为的目录 '.git'
  • 在该目录中创建一个"裸仓库"
  • 在其中创建一个post-receive文件'.git/hooks'并chmod其权限
  • 将实时服务器添加为远程服务器
  • 推送到实时服务器和GitHub

打开终端并输入以下内容ssh到您的实时服务器:

ssh root@your.ip.address.here # the password will be your root password
Run Code Online (Sandbox Code Playgroud)

询问您的主机在您的服务器上安装git的首选方法并执行此操作

创建目录,裸仓库和后接收文件

[root@host /home/username/public_html] mkdir testdir
[root@host /home/username/public_html] cd testdir
[root@host /home/username/public_html/testdir] mkdir .git
[root@host /home/username/public_html/testdir] cd .git
[root@host /home/username/public_html/testdir/.git] git init --bare
[root@host /home/username/public_html/testdir/.git] cd hooks
[root@host /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
[root@host /home/username/public_html/testdir/.git/hooks] chmod +x post-receive
[root@host /home/username/public_html/testdir/.git/hooks] exit
Run Code Online (Sandbox Code Playgroud)

在终端中,在本地存储库中,将您的实时服务器添加为远程服务器:

[username@yourhostname Program_One] # make sure you are in your local repository
[username@yourhostname Program_One] git remote add my_great_remote root@your.ip.address.here:/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’.
Run Code Online (Sandbox Code Playgroud)

将名为"my_text_file.txt"的文本文件添加到本地存储库,然后在终端中键入以下内容:

[username@yourhostname Program_One] # make sure you are in your local repository
[username@yourhostname Program_One] git add -all
[username@yourhostname Program_One] git status
[username@yourhostname Program_One] git commit -m "added text file"
[username@yourhostname Program_One] git push -u origin master
[username@yourhostname Program_One] git push -u my_great_remote master
Run Code Online (Sandbox Code Playgroud)

然后,post-receive文件将本地存储库中的文件复制到'testdir'目录,允许您访问以下文本文件:

mysite.com/testdir/my_text_file.txt
Run Code Online (Sandbox Code Playgroud)