Maintaining website code with Git?

Associate
Joined
14 May 2012
Posts
390
Location
London
Hey there,

I use bitbucket as a git repository and i'm aware there is a way to deploy that code to my live server. I just cant work out how, Can anyone help with a bit of a step by step idiot guide to deploying from bitbucket to a shared host? ( Tsohost in my case )
 
Permabanned
Joined
9 Aug 2009
Posts
12,236
Location
UK
You've found 'the difficult bit'.

I use a combination of msbuild tasks and ftp - but there are things like Go BuildServer that claim to do something similar in an automated way.
 
Associate
Joined
17 Oct 2002
Posts
730
Give ftploy.com a go, great little service for deploying via bitbucket or github via ftp, so ideal for shared hosting where you might not have ssh access.
 
Associate
Joined
9 May 2005
Posts
121
Location
Yorkshire
If you have SSH access to the servers then this isn't actually too hard, there are a few things you need to make sure though

1) Your source code will work on the server. Sounds obvious but your code needs to work 'as is' on the server and any custom config files must be gitignored (including files generated by any install scripts). Otherwise anytime you try to do a git pull you will have unstaged files

2) Further to the above you need to think about security. If you have install scripts in your repo then you may need to have them in a non-accessible folder (ie not in public_html) and then copy them into public_html to run the install (and then delete them so you don't have unstaged files)

Once this is done, there are a few more things to do:

1. In order to do this if you can connect to the server via SSH then you need to setup SSH keys for the server to authenticate with github/bitbucket (I'm not familiar how this works for bitbucket)

2. Setup a git repository and pull. One thing to note here is that git may not be available via the 'git' command, you may need to use usr/bin/git or similar (ask the hosts)
Code:
git init
git remote add origin REPONAME
git pull origin master

3. You may also need to run some chmod commands in order to get the file permissions running correctly.

If you are happy to manually deploy ) then everytime you do a git commit & push you just need to SSH connect to the server and run git pull origin master. However if you want automatic deployment then this is more complicated. In short there are several ways and looking on stackoverflow will give you multiple solutions.

Of course, this is just the way I have been doing things for a few projects, there are many ways of doing it. One quick note is that I have a 'public_html' inside my repository so that none of the git files are available in a publicly accessible directory.
 
Caporegime
Joined
18 Oct 2002
Posts
29,491
Location
Back in East London
Use `git archive` to export the files, then push to the server in your usual manner. Should be quite simple to knock this into a bash script or similar to make it a one-click deploy.

Otherwise you could clone onto the webserver itself and pull changes.
 
Last edited:
Back
Top Bottom