如何从本地存储库推送到GitHub和实时服务器? [英] How to push to both GitHub and live server from local repository?
问题描述
我是git的新手,但是GitHub已经创建了一个本地仓库,可以在输入时更新GitHub存储库:
[username @ yourhostname程序] git add。
[username @ yourhostname程序] git status
[username @ yourhostname程序] git commit -m消息
[username @ yourhostname程序] git push -u原点大师
我希望能够做的下一件事是让我做出更改并推送它们,这些都是也反映在现场的一个目录中。
我在live服务器上安装了git,并在那里建立了一个名为'testdir'
的目录。
当我在这个目录中看到'git init'
时,我也想在网页上看到引用到'git init --bare'
并且有点困惑。
如果任何人都可以提供一个一步一步的命令列表,以使我能够将本地存储库中所做的更改推送到GitHub和活动服务器,我将不胜感激。
这些是我的步骤和证明:
>
以下假设您:
- 已经在GitHub上设置了一个远程,并且可以推送更改
- 在本地资源库中的一个名为
'Program_One'
- 检查你是否有ssh访问你的活服务器
- 在您的服务器上安装git
- 创建目录
'testdir'
at'yoursite.com/testdir'
- 在该目录中创建一个名为
'的目录。
- 在该目录中创建一个裸回购
- 在
中创建一个后接收文件。混帐/ hooks'
并chmod权限
- 将实时服务器添加为远程服务器
- 推送到实时服务器和GitHub
- 在该目录中创建一个裸回购
这个过程包括8个步骤:
打开您的终端并输入以下内容以ssh登录您的实时服务器:
ssh root@your.ip.address.here#密码将是您的root密码
向您的主机提供在您的服务器上安装git的首选方法,并执行此操作 创建目录,裸露的repo和post-receive文件
[root @ host / home / [root @ host / home / username / public_html / testdir] mkdir .git
[root @ host / home / username / public_html] 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 / publi c_html / testdir / .git / hooks] vi post-receive
#按'i',粘贴以下2行,替换您的详细信息
#!/ bin / sh
GIT_WORK_TREE = / home / username / public_html / livetest git checkout -f
#按'esc',键入:w,按回车,键入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
在终端中,在您的本地存储库中,将您的实时服务器添加为远程服务器:
[username @ yourhostname Program_One]#确保您位于本地存储库
[username @ yourhostname Program_One] git remote add my_great_remote root@your.ip.address.here: /home/username/public_html/livetest/.git
#将'my_great_remote'更改为您想要调用远程的名称,注意github remote被称为'origin'。
将名为'my_text_file.txt'的文本文件添加到本地存储库,然后键入在终端中:
[username @ yourhostname Program_One]#请确保您位于本地存储库
[username @ yourhostname Program_One] git add -all
[username @ yourhostname Program_One] git status
[username @ yourhostname Program_One] git commit -m添加文本文件
[用户名@ yourhostname Program_One] git push -u origin master
[username @ yourhostname Program_One] git push -u my_great_remote master
post-receive文件会将您本地存储库中的文件复制到'testdir'目录,以便您访问以下文本文件:
mysite.com/testdir/my_text_file.txt
I'm new to git and GitHub however have set up a local repository that updates the GitHub repository when I type:
[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
The next thing I want to be able to do is make it so that when I make changes and push them, these are also reflected in a directory on a live site.
I have installed git on the live server and set up a directory there called 'testdir'
.
I am tempted to just type 'git init'
when in this directory but am also seeing references on the web to 'git init --bare'
and getting a bit confused.
I'd appreciate it if anyone could provide a step by step list of commands to enable me to push changes made in a local repository to both GitHub and a live server.
These were my steps and demonstrate:
- Adding a text file to a local repository
- Pushing these changes (ie the new file) to both GitHub and a live server
The following assumes that you:
- have already set up a remote at GitHub and can push changes there
- Are working in a directory in your local repository called
'Program_One'
This process includes 8 steps:
- Check if you have ssh access to your live server
- Install git on your live server
- Create the directory
‘testdir’
at'yoursite.com/testdir'
- Create a directory in that directory called
'.git'
- Create a ‘bare repo’ in that directory
- Create a post-receive file in
'.git/hooks'
and chmod its permissions - Add a live server as a remote
- Push to the live server and GitHub
Open your terminal and enter the following to ssh into your live server:
ssh root@your.ip.address.here # the password will be your root password
Ask your host the preferred way to install git on your server and do that
Create directories, bare repo and post-receive file
[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
in the terminal, in your local repository, add your live server as a remote with:
[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’.
add a text file called ‘my_text_file.txt’ to your local repository and then type the following in the terminal:
[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
the post-receive file will then copy files in your local repository to the ‘testdir’ directory allowing you to access the text file at:
mysite.com/testdir/my_text_file.txt
这篇关于如何从本地存储库推送到GitHub和实时服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!