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:
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:
--bare Git repo on the remote (so I can access it from everywhere)master (HEAD)
scp -r copy the --bare git repo from the remote server into my remote live domain stage.example.com
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.
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 the live branchThe difference between a post-receive and a post-update hook is that the post-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 or git --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, unset GIT_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`.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With