1

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?

Community
  • 1
  • 1
PedroKTFC
  • 745
  • 10
  • 28

2 Answers2

6

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

Community
  • 1
  • 1
adharris
  • 3,591
  • 1
  • 21
  • 18
  • 1
    Thanks. You pointed me in the direction where I eventually found the perfect solution here: http://blog.woodylabs.com/2012/01/1and1-web-hosting-git-installing-it-for-singular-dev/ (it's a little specific for 1and1 but references the original idea which isn't). Now my problem is how I also push submodules! :o) – PedroKTFC Feb 22 '13 at 14:33
1

Git is not (originally) meant for synchronizing working copies but repositories that is Git's commits/branches/refs/etc.

What your want to do I would call a remote checkout. There is hundreds of other ways to do. I have two ideas: As you have setup an ssh-connection the big work is done:

1) use git and ssh

git push origin my_branch
ssh user@server "(cd remote-dir-where-your-repo-is; git checkout -f my_branch;)"

2) Use rsync

rsync -av . ssh://user@server/dir --exclude=.git
Patrick B.
  • 11,773
  • 8
  • 58
  • 101