Deploy using git pull

Philip Ivanov
Jan 31 · 2 min read

Task — automatically pull files from bitbucket git repo upon commit/merge to master.

Whenever there’s a need to deploy by means of an automated git pull, without the whole container, docker registry, aws overhead, the code below works best.

exec(“git pull master”);

Here are the step-by step instructions:

  1. Create a user on bitbucket with access to the desired repository.
  2. SSH to your remote server, where the code should be pulled to.
  3. Clone the repository into the desired directory:

git clone

4. Create a script (python, php or shell) — doesn’t matter. The “exec” command above is for php. Script should be accessible from the web.

5. Add a webhook to the repository on bitbucket, where the triggered url is the url of the php script.

All done! Now every time there’s a change to master, the code will be pulled by the remote server.

Why use username and password and not SSH keys?

— SSH keys won’t work for a number of reasons, but anyone is free to give it a shot and let us know how it went. Note, the script is executed by the webserver, which runs under it’s own user that naturally has no access to the private key. Trying to make the keys available for that user is not worth the headache.

Bitbucket's own documentation has an FTP example, why not use that?

— The whole FTP business is not secure and not that widely used. If one can avoid spinning up an FTP server, one probably should.

Below are a few search queries suggested by google, left here to help those seeking the solution to their problem :)

How to sync with git repository

Bitbucket pull via ftp sftp

Deploy using ftp sftp

Automate git pull

Simplest continuous integration

// Originally published at

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade