Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to set up git deployment to Staging and Production from BitBucket so they don't have working dir

We have a repo that contains 'develop' and 'master' branches among others. I have it set up so that I push new commits from my machine to the develop branch. I am currently the only developer but expect to have more in the future. I create a branch on my machine for a new feature, do the development, commit and merge that branch to develop on my machine and then push to develop in the Bit Bucket repo. I want to then push the code to our Staging server.

There should be no development on the Staging server so I don't need a working directory. I just want it simple - push the code to Staging and the changes are merged into the existing code. If some correction to the code in Staging is needed, that will be done in the original feature branch on my machine and committed, merged and and pushed to 'develop' on Bit Bucket and again pushed to Staging.

Likewise, once the code on the Staging server is verified, I need to merge the code into 'Master' from 'develop' and push to the Production server from 'Master' in a similar manner as I'm pushing to Staging. All simple and clean. 

A couple questions:

1. How to set up the git instances on Staging and Production servers for this scenario?

2. Production server code is an image from another machine and so it currently has a lot of "changes" both "modified" and "new". How do I convert this over from that to the set-up I'm talking about above? 

Note: This is a Laravel 8 framework with PHP 8 on Centos 8 machines.




1 answer

0 votes
Mark C Atlassian Team Feb 16, 2022

Hi @David Newey

Thank you for reaching out to the community.

For best practices, we do recommend managing your environments as branches within your repository.
In your case, you can have the following branches:

  • development
  • staging
  • production (or master)

The workflow would be: development > staging > production (or master)
If you want to have other branches (e.g. feature branches) you can merge them to the development branch first then continue the process.
For merging one branch to another, you can implement pull requests as well.

Now, when it comes to your servers, you can use Git and just simply clone your repository based on their environment.
For example:

  • For your Staging server, you can clone your repository and Git checkout to the staging branch
  • For your Production server, you can clone your repository and Git checkout to the production (or master) branch

After that, you can just do Git pull from your Staging or Production servers either manually or automatedly (e.g Using Bitbucket Pipelines) to get new updates.
Alternatively, you can also replace or overwrite a server's version using SSH or rsync commands just make sure you use the specific branch for the environment (staging or production). 

By doing this workflow, you can separate your Staging and Production servers based on repository branches.

Hope it helps and let me know if you have further questions.

Mark C

Suggest an answer

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

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,214 views 2 9
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