18 Aug 2017
When collaborating on a project with other developers it's advantageous to use version control software to make it easier to develop new features without overwriting each others code. The most popular version control software by far is Git. This tutorial will teach you how to host a Git repository in Bitbucket and connect to it from ShiftEdit.
Bitbucket is popular as it offers free hosting for public and private Git repositories. So sign up to Bitbucket and create a repository for your project.
Next up we need to clone our project into our hosting environment. I'll be presuming that we have a domain setup on a webserver with SSH/ SFTP access, but you could also use FTP.
Open an SSH session into the server. We'll need to generate an SSH key to allow access to push and pull from our repository.
Press enter to the prompts and then it will generate the key,
Display the public key contents (edit path accordingly)
# cat /home/user/.ssh/id_rsa.pub
Copy the output key and then paste it into Bitbucket (Settings -> SSH Keys -> Add key)
Back into SSH, navigate into the project folder (edit path accordingly)
# cd /home/sites/mysite.com/httpdocs
Clone the git repository into this folder (edit git path accordingly - you can get this from bitbucket repository page, also be sure to include the trailing full stop)
# git clone email@example.com:adamjimenez/helloworld.git .
Add the site into ShiftEdit, make sure the path points to the home directory (e.g. /home/sites/mysite.com/httpdocs)
One connected the Git panel should be active. From here you can branch, commit and sync with Bitbucket.
Explaining the Git workflow would require an article in itself, but at it's most simplest you would edit your files and then use the Git panel to create a commit.
Once you're finished, click the Git menu -> Sync, to sync your changes with Bitbucket.
Taking it further
In theory you and your fellow developers could work off of the same webspace. In practice you will probably want your own development areas so that you can work on your own features and commit when ready.
In order to do this your collaborators should also register on Bitbucket and you can then share the project with them.
You could set up a subdomain on your server for each of your developers using the same instructions outlined above.
The main website can be kept updated by running this from SSH:
# git pull
You can automate this command by setting up a webhook within Bitbucket: Settings -> Webhooks -> Add webhook
Point this to a url on the server that will trigger the git pull, e.g:
$json = file_get_contents('php://input');
$result = shell_exec('/usr/bin/git pull 2>&1');
Hopefully this tutorial has been useful but if you need any help please contact the mailing list.