In the previous post, we showed how to synchronize the local repository with the remote repository located at Bitbucket cloud. For that we used a single branch called “master” locally and a branch called “origin/master” remotely. This branch can be shared with other users so that they can also clone the repository and do their work in their machines. Once they are done with their updated files, they can stage, commit and push it to remote branch. However, in a business I.T. development environment with multiple users are working together, it would be better to keep multiple branches. This would keep the work flow streamlined into the different stages a project goes through.
Usually a project starts at the development (DEV) phase, then goes to quality analysis (QA or testing) phase. Once testing is completed, it can move to pre-production (PREPROD) phase and then finally to the production (PROD) phase which is the final destination of the project where it accomplishes its intended purpose. There could be few more additional stages in this type of work flow, but the DEV, QA and PROD are the most commonly used ones.
We should also note that when operations team notice any issues with the applications running at production, they might refer back to the developers, which will again trigger another set of development, quality analysis and production phases. The following screenshot shows some of these branches used in a typical environment. In order to keep up with these commonly used phases we can have branches release/DEV, release/QA, master (PROD). Also to keep a personal local branch, we can also have a purpose/task driven name such as “MyLocalBranch” or a branch with a reference number, etc. The following screenshot shows how the branches have been created with our sample scenario.
Creating Local Branches
Let us create a branch locally at sourcetree and then sync to remote (Bitbucket cloud). It is also possible to create branches at bitbucket cloud and then sync them as the local sourcetree branches.
1] At sourcetree window, click on the “Branch” icon in the top. This will open a new popup window “Branch”. Enter the name of the new branch (e.g. MyLocalbranch), make sure to check the option for “Checkout New Branch” is selected and then click on “Create branch” button.
This will create and checkout the new branch. Your folder where the repository is mapped now corresponds to this new branch.
2] Click on “Fetch” button to retrieve the currently existing files from the remote branches.
3] The branches that exist at remote will now appear at sourcetree under REMOTES.
4] Start working with the copies of files at local branch by updating existing files or adding new files as required for the tasks in hand.