Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Using Git clone for live deployment

I've been researching into a simple Git clone for live deployment, using the following method:

Could Sourcetree handle this, instead of SSH, and could it be set up automatically (bearing in mind I'm rubbish with command line Git)? It'd save me a ton of hassle, I know Git has a simple url hook but Bitbucket post functionality is over my head.



2 answers

1 accepted

1 vote
Answer accepted

Hey Rob, sorry for the delay on this one. I'll put this in an answer instead as it's quite detailed.

Your URL looks OK, however, are you certain that you've been dropped into the right directory as you're using a relative URL there. It might be better to do Also, SourceTree can create remote reposities, but at the moment only for GitHub and Bitbucket. See the screenshot below (this is because it uses API's to do so, it doesn't have access to run commands on the servers!)

a) If it's the origin remote then yes, you'll do "git init --bare". A 'bare' repository is a little bit magic in that as you say, it doesn't contain your working tree. This is very important because otherwise when you push changes to that remote doing a "git status" will make it think that files have been deleted after they've been pushed as they don't exist in the remote's working tree. As one of the devs here just said "It's everything except a working copy". Check out for a mode detailed explanation.

b) The article you've linked to shows a manual process whereby you clone the repository to a directory on your server and then pull the changes when you want to 'deploy' the site. It's a push-pull set of actions which seems the easiest way to do it. Now, what you can do is just SSH into your server and pull meaning you can do it all from the same terminal. But what's even better is that you can script this process. So, in response to your above comments:

- If you're pushing to a bare repository, then no it won't have a working copy so the files won't just 'be there' unfortunately. Check out my answer to your next point below.

- If it's a remote 'bare' repository then it's not quite the same as having all the files. It doesn't have a working copy remember, so it's a set of objects. Take a look at the following screenshot to see my remote directory which has loads of changesets:

Note I have "GitTest" and "GitTestRemote". The remote one is where I'm pushing my changes to, and that's the contents of the folder. So you won't have a bunch of files because there is no working copy as it's a bare remote.

In short, I think your best solution is to have a post-commit/push hook which connects via SSH to do a pull on the server provided you trust the master branch completely. From my experience, merging with a branch can cause more problems so it's usually better to merge-test-deploy. You could whip up a simple SSH-pull script that would be a one-stop-shop deployment solution, or use a post-push hook to do that.

Let me know your thoughts, happy to give further input :)

Hey Keiran, thanks for such a detailed response! I'm understanding your comments and get the following:

  • Bitbucket and Github are examples of "bare" remotes, i.e. explicitly used for collaboration and sharing.
  • Any situation where I serve or edit files calls for a regular local-style repository.
  • Media Temple uses that path as a quick link to domains folder, but your version looks safer.

Think hooks would help. Read a few tutorials on Git hooks and Github's URL post but Bitbucket's post hook looks complicated. Also read a couple of versions of scripts from simple PHP file pulls and a straight up bash script. So from this a couple of questions:

Where/how to serve script?

For secure passwords etc, my folder structure is:

/domain/.git --- /domain/html/<files> --- /domain/cgi-bin

Presuming I've cloned repository on live (assume it automatically checks out master):

  • Are there any easy to understand tutorials for SSH script to automatically pull when Bitbucket sees changes to master branch? Something failsafe, can only imagine this being a read only script.
  • Will this simply overwrite anything I have on the live server?

What is best Local > Staging > Live method?

The client will want to view changes before going live, there's a way to serve a site from localhost but involves being connected. Ideally I'd push changes to a staging server, and automation rather than FTP:

  • You mentioned it's a bad idea to work of branches, I use Git Flow so you'd want to serve the files from a branch on your staging server. Would it not be easy enough to have one script for staging (to check out work-in-progress), and one for live (only ever pulls master)?
  • What problems would I face trying to push changes from a live/staging server? Or using branches on Staging? Ability to merge client's Wordpress changes could be useful; could I do this from SourceTree?
  • Finally, using submodules, should you checkout "master" or a specific commit?

I rarely use terminal but can follow instructions!


  • Yes, Bitbucket and GitHub create bare remotes when you create a repository.
  • Yes, if you're wanting to make commits locally then it's a "non-bare" repository
  • It should be, yup!

The thing with your latter points is that it's not something we usually provide information for as it goes out of the bounds of SourceTree. This is a configuration issue specific to your server. There'll be many guides, and many tutorials all doing things in various different ways. They're all different because these kinds of setups are completely unique to your setup. We can't really write it or make suggestions for you. Basically, just do it in a way that works for you by testing each step at a time. Try out a very simple script that will simply pull the changes into that directory and iterate from there on out.

If you're pulling changes then git would stop to say you have local changes that need committing, so if there's environment-specific files then you'll want to ignore them.

No no, I didn't say it was a bad idea to work off branches. My point was regarding ensuring everything works after a merge. And I quote "From my experience, merging with a branch can cause more problems so it's usually better to merge-test-deploy" - basically, once you merge your changes if it merges two changesets for the same file then often in my case there'll be build errors.

There's always branches, so you'd always been pulling from some branch. Yes, use a staging branch perhaps and pull changes into your staging site from there, if OK then merge that branch into master, but you still need to test the merged changes are OK in some environment.

Regarding submodules, that depends on what you need from the repository ;)

SourceTree can push to any valid Git remote, so can definitely be used to deploy sites (Heroku is one of the sites that pioneered this approach originally). Really the main configuration you need to do is on the server, SourceTree can just push to whatever URL you give it so long as it's a valid git remote.

Hey Steve, yes I have looked into that way of working but it looks a wee bit technical for me ... what I was meaning was cloning without reqiring Git to be installed on the live server - I know this can be achieved via SSH but I'd prefer doing it in SourceTree if at all possible. Not quite sure how cloning affects previous clones, i.e whether it overwrites everything or just new files, and I think you can auto populate submodules when doing the clone ... I'd like to give it a shot anyway i.e:

I may have another crack at some tutorials setting up Git on a server but looks a bit of a pain on shared servers.

Actually, it seems Git is already on my MediaTemple (GS) account, so one or both of these tutorials may be enough - or of course, using SourceTree! Clone from Bitbucket, then pull latest master changes. Nice:

Save me a few bob with deployment. Would still be helpful to find out the info above however, how a clone to a non-git server would work. Imagine most clients hosts would be without.



Perhaps I'm just being dumb, but I'm still struggling with this. I kind of understand how to do this with terminal, but as for SourceTree I'm not quite sure. I understand a SSH git URL would look something like this: and fairly certain SourceTree can't actually create a remote repository for me.

I'm confused about the steps to "push" however ...

a) It seems reading this article that in order to push to a repository, it has to be (or should be) "bare". It also seems this may be the only way that SourceTree will be able to push any changes to it, although this article explains "bare repositories" a bit better and looks like as it doesn't hold working tree files it'd be useless on the deployment server.

b) However, reading this article via SSH looks way easier and includes the latest working files.

So it seems that the main difference is (b) seems to work like a regular local repository, whereas (a) doesn't hold working tree files and is just for tracking changes. How then would I use (b) with SourceTree? I'm assuming the way is once I've created the repository on the live server, to add it as a remote and push from the local repository, but I'm unsure of the following ...

- So long as I'm checked out on the correct master branch do I just push as if I were pushing to the Bitbucket repository, changing the url for the one above in italics?

- And will it contain the latest version of the files without having to do further checkouts on the live server?

Thanks, hopefully you can save me from going mad!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in DevOps

GitHub Script with GitHub Actions Automating Workflows

Hello folks, This is a series of articles where I explain GitHub Script with GitHub Actions and how you can automate publishing data on Atlassian & GitHub Platform based on the results of Workf...

98 views 1 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you