Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

drupal - How to use git locally and push to remote server

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:

  • 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).

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Then, to deploy,

git push production branch

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...