如何在本地使用git并推送到远程服务器 [英] How to use git locally and push to remote server

查看:122
本文介绍了如何在本地使用git并推送到远程服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用git来管理我的开发,集成测试和生产环境。我已经环顾四周,但似乎找不到一个简单的解释,如何(例如 Git推到远程存储库并不完全相同)。对我想做的事情的一个很简单的解释:

I want to use git to manage my development, integration test and production environments. I've looked around but can't seem to find a simple explanation of how (eg Git - pushing to remote repository doesn't quite do it). A very brief explanation of what I want to do:


  • 我掌握了我笔记本电脑上的代码库,因为这是我做大部分工作的地方。

  • 我在1and1上托管我的网站。在那里,我有两个网站设置,生产站点和集成测试站点。

  • 我想设置git,所以我可以在我的笔记本电脑上有两个遥控器,说siteprod和siteint

  • 每当我有一个分支机构,我想测试一下,我想从笔记本电脑中推出,说使用git push siteprod newproductionversion(我确定你得到这个想法)。

  • I master my codebase on my laptop as that's where I do most of my work.
  • I host my site on 1and1. On there, I have two sites set up, the production site and an integration test site.
  • I want to set up git so I can have two remotes on my laptop, say siteprod and siteint.
  • Whenever I have a branch I want to test, I want to push it from my laptop, say using "git push siteprod newproductionversion" (I'm sure you get the idea).

我已经通过使用git --init(注意没有--bare!)和设置在1and1上创建一个存储库使用ssh启动遥控器。但是我必须设置receive.denyCurrentBranch来忽略,一旦我推,我必须通过登录到1and1服务器来检出分支。我必须重复一下整合环境。

I've achieved something close by creating a repository on 1and1 using git --init (note without --bare!) and setting up the remotes using ssh. But I have to set receive.denyCurrentBranch to ignore and once I've pushed, I have to checkout the branch by logging onto the 1and1 server. I have to repeat it all for the integration environment.

这看起来很笨拙,但我相信我的用例并不常见。有一个明智的做法吗?

This seems very clumsy but I'm sure my use case is not at all unusual. Is there a sensible way of doing this?

推荐答案

如果你有ssh连接到服务器,你可以直接添加一个git远程到服务器上的存储库。如下所示:

If you have ssh connection to the server, you can add a git remote directly to the repository on the server. Something like:

git add remote production sshUser@example.com:/path/to/repo/.git

然后,部署

git push production branch

说,你可能不应该提供你的生产代码从git存储库。更好的是在您的网页上设置 之外的存储库,并使用 post-receive 挂钩将代码复制到Web根目录。这似乎在这里概述:
使用Git推送部署项目

That said, you probably shouldn't have your production code served from a git repository. Much better is to set up a repository outside your web root and use a post-receive hook to copy the code to the web root. This appears to be outlined here: Deploy a project using Git push

这篇关于如何在本地使用git并推送到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆