but can't figure out how to set up git to push from local to remote when the remote files are above the webroot.
To setup the repos, you will need an intermediate repo to serve as the reference point. Now this repo could be on a hosting site like github
or bitbucket
, or it could be a bare repo on your server itself. (Note - bitbucket has free private repos for small number of users)
The advantage of a bare repo is that you can circumvent any issues related to setting up ssh
mechanism between the server, the online service and your dev machine. The cons would be losing all the code on the server in case your server goes down, though you will still have a copy of it on your dev machine, so not all will be lost.
Step 1
So let us assume you move ahead with a bare repo. Ignore this step if you will be using bitbucket/github.
For this, we need to create a bare repo as follow on your server:
ssh user@myserver
cd /some/isolated/location
git init --bare intermediate_repo.git
This creates an intermediate repo with path /some/isolated/location/intermediate_repo.git
.
Next, cd inside this bare repo, and run the following commands, so that you can access the repo over ssh as a git server
cd intermediate_repo.git
mv hooks/post-update.sample hooks/post-update
chmod a+x hooks/post-update
git update-server-info
So now your bare
repo is good to go as the intermediate repo, and we can add it as remote in other repositories.
Step 2
Now in your dev
machine, add a remote (Step2)
git remote add intermediate ssh://user@myserver:/some/isolated/location/intermediate_repo.git
Step 3
And on your server
s repo, add a remote
ssh user@myserver
cd /repo/location
git remote add intermediate /some/isolated/location/intermediate_repo.git
Step 4
So now you are good to go ().
You can push your code as following from your dev machine
git push intermediate branchname
and pull it into your configured code repo as
ssh -t user@myserver "cd /repo/location && git pull intermediate branchname"
PS
If you choose to go with a bitbucket installation, then skip step 1, and in steps 2 & 3 above, replace the url
/path
with the bitbucket ssh url. Check out this bitbucket link for setting up ssh access with bitbucket. Also, while generating ssh keys, generate them without passphrases, otherwise you might have to debug more stuff around ssh and passphrases.
Your Views
folder should be available to you at location /repo/location/Views
, which you can configure for webroot access.