将 Git 分支直接推送到实时服务器目录中,以便实时查看文件
如何在 Git 中设置远程目录,以便可以在本地将阶段分支推送到远程并查看临时服务器(例如 stage.example.com)上的实时更改?
我的想法(我放弃 SVN 的部分原因)是我可以(本地)维护 3 个不同的“主”分支,如下所示:
- master - 用于本地开发,工作目录
- stage - 应该与登台服务器目录同步(远程)
- live - 这应该是可公开访问的网站(远程)
我的想法(以及其他人声称是可能的)是我可以从本地计算机维护这些远程“站点”,而无需不断登录远程服务器 shell 并运行 svn update(在我当前的 svn 工作流程中,我需要一直这样做...... )或者当然在我的 Git 工作流程中在远程运行 git pull 。
如何设置远程目录,以便可以在本地将我的 stage
分支推送到 staging 远程服务器
并查看上的更改(例如) 立即stage.example.com
?
然后,一旦stage
一切正常并经过测试,我就可以在本地push
到live
远程进行我已经测试过的这些更改在舞台
上访问实时网站。
这是否可以完成,或者我在这里得到了一些疯狂的想法,而这些想法根本不适合用 Git 完成?
如果这很重要,这里有一些关于我的本地和远程服务器的统计信息:
remote server: Dreamhost (shared account) remote GIT version: 1.7.1.1 remote GIT client: shell local computer: Mac Pro (Snow Leopard 10.6.6) local GIT version: 1.7.2.3 local GIT client: Tower.app // git-tower.com
另外,到目前为止我已经不成功尝试了以下工作流程:
- 创建一个
--bare
Git远程存储库(这样我就可以从任何地方访问它) - 将此远程存储库克隆到本地目录并使用 Git Tower 应用程序来管理它
- 在
master (HEAD)
本地工作 scp -r
将--bare
git repo 从远程服务器复制到我的远程活动域stage.example.com
- 将远程添加到本地工作副本,然后尝试推送to
origin/stage
显然这不起作用,但我不知道为什么或如何做得更好。
我有 SVN 背景,对 Git 很陌生,但看过很多教程(Peepcode 和 ThinkVitamin),但仍然不知道如何设置。
How can I set up remote directories in Git where I can locally push a stage branch to the remote and see the live changes on a staging server, like stage.example.com?
The notion I have (part of why I am moving away from SVN) is that I can maintain (locally) 3 different "main" branches as follows:
- master - used for local development, working dir
- stage - should be in-sync with staging server directory (remote)
- live - this should be the publicly accessible website (remote)
The idea I have (and what others claim is possible) is that I can maintain these remote "sites" from my local computer without having to constantly log into my remote server shell and run svn update
(in my current svn workflow I need to do this all the time…) or of course in my Git workflow run git pull
on the remote.
How can I setup the remote directories so that I can locally push my stage
branch to the staging remote server
and see the changes on (for example) stage.example.com
right away?
Then once the stage
is all okay and tested I would just locally be able to push
to the live
remote to make these changes that I have tested on the stage
to the live website.
Can this even be done or am I getting crazy ideas here that are simply not meant to be done with Git?
In case this is of importance here are a few stats about my local and remote servers:
remote server: Dreamhost (shared account) remote GIT version: 1.7.1.1 remote GIT client: shell local computer: Mac Pro (Snow Leopard 10.6.6) local GIT version: 1.7.2.3 local GIT client: Tower.app // git-tower.com
Also, so far I have unsuccessfully tried the following workflow:
- Create a
--bare
Git repo on the remote (so I can access it from everywhere) - Clone this remote repo to a local directory and the use Git Tower app to manage it
- Work locally in
master (HEAD)
scp -r
copy the--bare
git repo from the remote server into my remote live domainstage.example.com
- Add remote to local working copy and then try to push to
origin/stage
Clearly this doesn't work but I don't know why or how to do it any better.
Coming from a SVN background I'm new to Git but have watched plenty of tutorials (Peepcode & ThinkVitamin) but still cannot figure out how to set this up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 DVCS(“分布式”VCS,如 Git 或 Mercurial)实现的一个概念是它添加发布的概念(推/拉)到分支的概念。
CVCS(“集中式”VCS,如 SVN)只有分支(以及一个要推送到服务器上的中央存储库)。
在您的情况下,暂存或实时是发布步骤,即不同的 Git 存储库准备好接收您想要在暂存或实时环境中看到的修改。
这意味着:
staging
”分支)或实时(“live
”分支)的内容staging
或live
分支您还可以将裸存储库克隆到您需要使用的任何其他本地计算机。
post-receive
和post-update
挂钩之间的区别在于,post-update
挂钩针对每个修改的分支执行一次:< br>请参阅“Git hook 根据推送到远程服务器的分支更新各种 Web 文件夹”SO 问题。
在初始推送时,执行“
git push --all origin
”,所有分支都将在远程裸存储库上创建。这个想法是服务器端不应该涉及拉动:只有 git --work-tree=/path/to/your/live/files/ checkout live 或 git --work -tree=/path/to/your/staging/files/ checkout staging,取决于更新后挂钩的参数:您只需将裸存储库的文件检出到服务器上的这些“文件夹”中。
如果您为挂钩编写 ruby 脚本,请确保:
#!/usr/bin/env ruby
,`git ...`
, 就像在这个脚本中一样,ENV[' HOME']
在所述脚本中指定当前用户的主目录,如果您需要诸如`cd ~/stagedomain.com`
或`--work-tree= 之类的命令~/stagedomain.com`
工作(将`~`
设置为正确的路径),git pull
,请取消设置GIT_DIR
与其他命令位于同一行就像您的其他问题:`cd ~/stage.mydomain.com &&取消设置 GIT_DIR && git pull core stage`
。The one notion to realize with a DVCS ("Distributed" VCS, like Git or Mercurial) is that it adds the notion of publication (push/pull) to the notion of branching.
A CVCS ("Centralized" VCS, like SVN) has only branching (and one central repo to push to on a server).
In your case, staging or live are publication steps, i.e. different Git repo ready to receive the modifications you want to see in staging or in live environment.
That would mean:
staging
" branch) or live ("live
" branch)staging
or thelive
branchYou can also clone the bare repo to any other local computer you need to work on.
The difference between a
post-receive
and apost-update
hook is that thepost-update
one is executed once for every branch modified:See the "Git hook to update various web folders based on branch pushed to remote server" SO question.
On the initial push, do a "
git push --all origin
" and all branches will be created on the remote bare repo.The idea is no pulling should be involved on the server side: Only a
git --work-tree=/path/to/your/live/files/ checkout live
orgit --work-tree=/path/to/your/staging/files/ checkout staging
, depending on the parameters of the post-update hook: you only checkout the files of the bare repo into these 'folders' on the server.If you do a ruby script for your hook, make sure to:
#!/usr/bin/env ruby
,`git ...`
, like in this script,ENV['HOME']
to specify the homedir of the current user within said script, if you want commands like`cd ~/stagedomain.com`
or`--work-tree=~/stagedomain.com`
to work (with`~`
being set to the right path),git pull
, unsetGIT_DIR
on the same line than the other commands like in your other question:`cd ~/stage.mydomain.com && unset GIT_DIR && git pull core stage`
.