Skip to content

Bitbucket Git Workflow for Developers: Complete PHP & Laravel Guide

44 people viewed this

Bitbucket Git Workflow for Developers: Complete PHP & Laravel Guide

Bitbucket Git Workflow for Developers — Complete Guide for PHP & Laravel Projects

If you work as a PHP or Laravel developer in a team, knowing individual Git commands is not enough.

You also need to understand how Git is used as part of a real development workflow.

A typical Bitbucket-based development workflow looks like this:

Clone Repository
      ↓
Create Feature Branch
      ↓
Write Code
      ↓
Test
      ↓
Commit
      ↓
Push to Bitbucket
      ↓
Create Pull Request
      ↓
Code Review
      ↓
Resolve Feedback
      ↓
Merge
      ↓
Deploy

In this article, we will build this workflow step by step using practical PHP and Laravel examples.


1. What Is Bitbucket?

Bitbucket is a platform for hosting Git repositories and collaborating on software projects.

Developers can use it to manage:

  • Git repositories
  • Branches
  • Pull Requests
  • Code reviews
  • Repository permissions
  • CI/CD workflows
  • Team collaboration

For a Laravel application, the source code might be stored in a repository such as:

company/pharmacy-erp

Developers clone the repository, create feature branches, work locally, and push their branches back to Bitbucket for review.


2. Why Use a Git Workflow?

Imagine five developers directly modifying the same main branch.

Developer A → main
Developer B → main
Developer C → main
Developer D → main
Developer E → main

This can make collaboration difficult.

A branch-based workflow separates development work:

main
 │
 ├── feature/payment
 ├── feature/inventory
 ├── feature/customer
 └── fix/login

Each developer can work independently and submit changes for review.


3. Complete Bitbucket Git Workflow

A practical team workflow can be represented as:

Bitbucket Repository
        ↓
      Clone
        ↓
  Update Local Branch
        ↓
 Create Feature Branch
        ↓
    Write Code
        ↓
   Run Tests
        ↓
      Commit
        ↓
 Push Feature Branch
        ↓
 Pull Request
        ↓
 Code Review
        ↓
 Resolve Feedback
        ↓
     Approval
        ↓
      Merge
        ↓
      Deploy

Let's understand every step.


4. Step 1 — Clone the Bitbucket Repository

First, clone the project to your local machine.

For example:

git clone git@bitbucket.org:company/pharmacy-erp.git

Enter the project:

cd pharmacy-erp

Check the repository:

git status

Check the remote:

git remote -v

You might see:

origin  git@bitbucket.org:company/pharmacy-erp.git (fetch)
origin  git@bitbucket.org:company/pharmacy-erp.git (push)

5. Step 2 — Install the Laravel Project

After cloning a Laravel application, install the dependencies if required:

composer install

Create the environment file:

cp .env.example .env

Generate the application key:

php artisan key:generate

Configure the database in .env and run the required migrations:

php artisan migrate

Then run the application:

php artisan serve

The exact setup can differ between projects, so always follow the project's README and team documentation.


6. Step 3 — Update Your Local Repository

Before creating a feature branch, make sure your starting branch is up to date.

For example:

git switch develop

git fetch origin

git pull origin develop

Some teams use a different integration strategy, such as:

git pull --rebase origin develop

Follow the workflow configured by your team.


7. Step 4 — Create a Feature Branch

Never start a new feature directly on the shared branch unless your team explicitly uses that workflow.

Create a feature branch:

git switch -c feature/payment

Older Git syntax also supports:

git checkout -b feature/payment

Now your branch is:

develop
   │
   └── feature/payment

8. Good Branch Naming

Use clear and consistent branch names.

Examples:

feature/payment
feature/customer-search
feature/invoice-report

fix/login-validation
fix/payment-calculation

hotfix/payment-failure

refactor/payment-service

chore/update-dependencies

Avoid vague names such as:

test
new
changes
mybranch
final
final2

A good branch name tells the team what the branch is about.


9. Step 5 — Develop the Feature

Now work on your Laravel feature.

Suppose you are implementing a payment service:

app/Services/PaymentService.php

You might also add:

app/Http/Controllers/PaymentController.php

app/Models/Payment.php

database/migrations/xxxx_create_payments_table.php

tests/Feature/PaymentTest.php

During development, regularly check:

git status

10. Step 6 — Review Your Changes

Before committing, inspect what you changed.

For unstaged changes:

git diff

For staged changes:

git diff --staged

Also check:

git status

This helps prevent accidentally committing:

  • .env
  • Debug files
  • Temporary files
  • IDE configuration
  • Generated files that should not be committed
  • Unrelated changes

11. Step 7 — Run Tests

Before creating a commit, test your Laravel changes.

php artisan test

You might also run specific tests:

php artisan test tests/Feature/PaymentTest.php

Depending on your project, you may also run:

php artisan pint

or other project-specific static analysis, linting, and quality checks.


12. Step 8 — Stage Your Changes

Stage the files you want to commit.

For a specific file:

git add app/Services/PaymentService.php

For multiple files:

git add app/Services/PaymentService.php
git add tests/Feature/PaymentTest.php

Or, when you have reviewed all changes and intend to include them:

git add .

Then verify:

git status

13. Step 9 — Create a Good Commit

Create a meaningful commit:

git commit -m "feat(payment): add payment service"

Good commit messages explain the purpose of the change.

Examples:

feat(payment): add payment gateway integration

fix(invoice): correct invoice total calculation

refactor(order): move order logic to service

test(payment): add payment feature tests

docs(api): update authentication documentation

14. One Commit vs Multiple Commits

Don't create one huge commit for unrelated work.

Bad:

git commit -m "changes"

The commit may contain:

  • Payment changes
  • Customer changes
  • CSS changes
  • Database changes
  • Unrelated bug fixes

Instead, keep commits logically organized.

feat(payment): add payment service

test(payment): add payment tests

15. Step 10 — Push the Feature Branch

After committing:

git push -u origin feature/payment

The -u option establishes tracking between the local and remote branch.

After that, you can normally use:

git push

for future pushes from that branch.


16. What Happens in Bitbucket?

After pushing:

git push -u origin feature/payment

Bitbucket now has the branch:

feature/payment

Your repository might look conceptually like:

main
develop
feature/payment ← your branch

You can then create a Pull Request according to your team's repository workflow.


17. Step 11 — Create a Pull Request

A Pull Request allows your team to review the changes before merging them.

A typical Pull Request might be:

feature/payment
        ↓
      develop

The Pull Request should explain:

  • What was changed?
  • Why was it changed?
  • How was it tested?
  • Are there database changes?
  • Are there configuration changes?
  • Are there known limitations?

18. Good Pull Request Description

For example:

Title:
Add payment gateway integration

Summary:
- Added PaymentService
- Added payment API integration
- Added payment validation
- Added feature tests

Testing:
- php artisan test
- Payment feature tests passed

Database:
- Added payments table migration

A clear Pull Request makes code review easier.


19. Step 12 — Code Review

Another developer or reviewer examines your Pull Request.

They may check:

  • Code quality
  • Architecture
  • Security
  • Performance
  • Database queries
  • Tests
  • Naming
  • Error handling
  • Laravel conventions

They may leave comments such as:

"Can this logic be moved into PaymentService?"

"Please add a test for failed payments."

"Could this query cause an N+1 problem?"

Review comments are part of the development process, not necessarily a sign that the code is unusable.


20. Step 13 — Make Changes Requested During Review

Suppose the reviewer asks you to add validation.

Modify the code locally:

app/Http/Requests/PaymentRequest.php

Run tests:

php artisan test

Commit:

git add .

git commit -m "fix(payment): add payment validation"

Push:

git push

The Pull Request is automatically updated with the new commit.


21. Step 14 — Keep Your Feature Branch Updated

While your Pull Request is open, other developers may merge changes into develop.

Your feature branch may become behind.

First fetch:

git fetch origin

Then update your feature branch using your team's preferred strategy.

For example, merge:

git merge origin/develop

Or, when your team permits and expects rebasing:

git rebase origin/develop

Resolve any conflicts, run tests, and push according to the chosen workflow.


22. Handling a Merge Conflict

Suppose you run:

git merge origin/develop

and Git reports:

CONFLICT (content):
Merge conflict in app/Services/PaymentService.php

Check:

git status

Open the conflicted file. You may see:

<<<<<<< HEAD

Your changes

=======

Changes from develop

>>>>>>> origin/develop

Choose or combine the correct code.

Then:

git add app/Services/PaymentService.php

If you are completing a merge:

git commit

If you are in a rebase workflow:

git rebase --continue

Run your tests after resolving the conflict.


23. Aborting a Merge

If a merge becomes complicated and you want to return to the state before the merge:

git merge --abort

For a rebase:

git rebase --abort

Use the command matching the operation currently in progress.


24. Typical Branching Strategy

A simple team structure could be:

main
  ↑
  │
develop
  ↑
  ├── feature/payment
  ├── feature/inventory
  ├── feature/customer
  └── fix/login

In some teams, developers work directly from main using short-lived feature branches.

Other teams maintain additional branches such as:

main
develop
release/*
hotfix/*
feature/*

The exact branching strategy should be defined by the project rather than copied blindly from another team.


25. Feature Branch Workflow

A feature branch workflow looks like:

develop
   │
   └── feature/payment
           │
           ├── commit
           ├── commit
           └── commit
                 │
                 ↓
            Pull Request
                 │
                 ↓
              develop

This keeps feature development separate from the shared branch until review and integration.


26. Bug Fix Workflow

For a normal bug:

git switch develop

git pull origin develop

git switch -c fix/payment-calculation

Fix the bug:

app/Services/PaymentService.php

Test:

php artisan test

Commit:

git add .

git commit -m "fix(payment): correct payment calculation"

Push:

git push -u origin fix/payment-calculation

Then create the Pull Request.


27. Hotfix Workflow

A production issue may require a faster workflow.

For example:

main
  │
  └── hotfix/payment-failure

Create:

git switch main

git pull origin main

git switch -c hotfix/payment-failure

Fix the issue.

Test carefully:

php artisan test

Commit:

git add .

git commit -m "hotfix(payment): handle gateway failure"

Push:

git push -u origin hotfix/payment-failure

Then follow your team's emergency Pull Request and release process.


28. Release Branch Workflow

Some teams use release branches.

develop
   │
   └── release/1.5.0

The release branch can be used for:

  • Final testing
  • Bug fixes
  • Release preparation
  • Documentation updates
  • Versioning

The exact merge-back strategy depends on the team's branching model.


29. Example — Complete Laravel Feature Workflow

Suppose you need to implement a pharmacy payment report.

Step 1 — Update develop

git switch develop
git pull origin develop

Step 2 — Create branch

git switch -c feature/payment-report

Step 3 — Develop

app/Http/Controllers/PaymentReportController.php
app/Services/PaymentReportService.php
resources/views/payments/report.blade.php

Step 4 — Test

php artisan test

Step 5 — Review changes

git status
git diff

Step 6 — Commit

git add .

git commit -m "feat(payment): add payment report"

Step 7 — Push

git push -u origin feature/payment-report

Step 8 — Create Pull Request

feature/payment-report
          ↓
       develop

Step 9 — Address review comments

git add .
git commit -m "fix(payment): address review comments"
git push

Step 10 — Merge

After required approvals and checks pass, the Pull Request is merged according to the team's policy.


30. What Should Never Be Committed?

A professional Git workflow also means knowing what should stay out of the repository.

For Laravel applications, commonly excluded files include:

.env

The exact exclusions depend on the project, but a Laravel .gitignore typically prevents environment-specific or generated files from being committed.

Before committing, always inspect:

git status
git diff --staged

Never assume that git add . means every file is safe to commit.


31. Database Migration Workflow

Suppose your Laravel feature requires a database change.

Create a migration:

php artisan make:migration add_status_to_payments_table

Run it locally:

php artisan migrate

Commit the migration:

git add database/migrations

git commit -m "feat(payment): add payment status migration"

Push it with the rest of the feature branch.

The deployment process should run migrations according to your team's controlled production procedure.


32. Composer Changes in Git Workflow

Suppose you install a Laravel package:

composer require vendor/package

This may modify:

composer.json
composer.lock

Review both:

git diff
git diff --staged

Commit them when they are part of the feature:

git add composer.json composer.lock

git commit -m "feat(payment): add payment package"

33. Pull Request Checks

Before merging a Pull Request, a team may require:

  • Successful automated tests
  • Code review approval
  • Successful build
  • Static analysis
  • Linting
  • Security checks
  • Successful deployment checks

The exact checks depend on the repository's CI/CD configuration.


34. Bitbucket Pipelines

A team may also configure automated CI/CD using Bitbucket Pipelines or another CI system.

For example, after pushing:

git push origin feature/payment

automated checks may run:

 
Push
 ↓
Build
 ↓
Install dependencies
 ↓
Run tests
 ↓
Static analysis
 ↓
Report result
 

The Pull Request can then be reviewed with those checks in mind.

 

 

35. What Happens After Merge?

 

A typical flow is:

 
Feature Branch
      ↓
Pull Request
      ↓
Review
      ↓
Approval
      ↓
Merge to develop
      ↓
Testing/Staging
      ↓
Release
      ↓
Production
 

Some teams deploy directly from main, while others have separate staging and production branches or deployment mechanisms.

 

 

36. What If the Pull Request Has Conflicts?

 

If Bitbucket reports that your branch cannot be cleanly merged, update your local branch.

 

For example:

 
git fetch origin

git switch feature/payment

git merge origin/develop
 

Resolve conflicts.

 
git status
 

Then stage the resolved files:

 
git add .
 

Complete the merge:

 
git commit
 

Run tests:

 
php artisan test
 

Push:

 
git push
 

The Pull Request should then reflect the updated branch.

 

 

37. Should You Commit Directly to main?

 

Whether direct commits to main are allowed depends on repository policy.

 

In many professional teams, the main branch is protected and changes are introduced through Pull Requests.

 

A common workflow is:

 
Feature Branch
      ↓
Pull Request
      ↓
Review
      ↓
Checks
      ↓
Merge
      ↓
main
 

Branch protection and required approvals should be configured according to the team's needs.

 

 

38. How to Keep Your Branch Clean

 

Before pushing:

 
git status
git diff
git log --oneline -5
 

Look for:

 
  •  
  • Unrelated files
  •  
  • Debug statements
  •  
  • Temporary code
  •  
  • Accidental credentials
  •  
  • Large generated files
  •  
  • Incorrect commit messages
  •  
 

A clean branch makes review easier.

 

 

39. Common Bitbucket Git Mistakes

 

❌ Mistake 1 — Working directly on develop

 

Create a feature or fix branch instead when the team workflow requires it.

 

❌ Mistake 2 — Pushing without testing

 
git push
 

should normally come after appropriate local testing.

 

❌ Mistake 3 — Using git add . without reviewing

 

Always check:

 
git status
git diff --staged
 

❌ Mistake 4 — Huge commits

 

Keep commits focused and meaningful.

 

❌ Mistake 5 — Ignoring Pull Request comments

 

Review feedback should be addressed or discussed before merging.

 

❌ Mistake 6 — Force pushing shared branches

 

Avoid rewriting shared history unless your team explicitly allows and understands it.

 

❌ Mistake 7 — Forgetting to update the feature branch

 

Long-lived branches can diverge significantly from the target branch.

 

 

40. Best Practices for Bitbucket Git Workflow

 
  •  
  • Keep feature branches focused.
  •  
  • Use meaningful branch names.
  •  
  • Write meaningful commit messages.
  •  
  • Pull or fetch regularly according to your team's workflow.
  •  
  • Keep Pull Requests reasonably focused.
  •  
  • Run tests before pushing.
  •  
  • Never commit credentials or sensitive environment files.
  •  
  • Review your staged changes.
  •  
  • Resolve conflicts carefully.
  •  
  • Use Pull Requests for shared branch changes when required.
  •  
  • Protect important branches.
  •  
  • Follow the project's deployment process.
  •  
 

 

41. Complete Daily Workflow for a Laravel Developer

 

Here is a practical daily workflow:

 
# Start from develop
git switch develop

# Get latest changes
git pull origin develop

# Create feature branch
git switch -c feature/customer-search

# Develop
# ...

# Check changes
git status
git diff

# Run tests
php artisan test

# Stage
git add .

# Review staged changes
git diff --staged

# Commit
git commit -m "feat(customer): add customer search"

# Push
git push -u origin feature/customer-search

# Create Pull Request in Bitbucket

# Address review comments
git add .
git commit -m "fix(customer): address review comments"
git push

# After approval
# Merge according to team policy
 

 

42. Complete Workflow Diagram

 
                BITBUCKET
                    │
                    ↓
              Clone Repository
                    │
                    ↓
              Local Repository
                    │
                    ↓
             Update develop/main
                    │
                    ↓
             Create Feature Branch
                    │
                    ↓
              Write Laravel Code
                    │
                    ↓
                Run Tests
                    │
                    ↓
                  Commit
                    │
                    ↓
              Push to Bitbucket
                    │
                    ↓
              Pull Request
                    │
                    ↓
                Code Review
                    │
              ┌─────┴─────┐
              │           │
           Changes      Approved
              │           │
              ↓           ↓
          Fix + Push     Merge
                          │
                          ↓
                       Testing
                          │
                          ↓
                       Release
                          │
                          ↓
                      Production
 

 

43. Bitbucket Git Workflow Cheat Sheet

 
Step Command / Action
Clone git clone <url>
Check status git status
Update branch git pull origin develop
Create feature branch git switch -c feature/name
Inspect changes git diff
Stage git add .
Commit git commit -m "message"
Push git push -u origin feature/name
Create Pull Request Bitbucket
Update feature branch git fetch origin + merge/rebase according to team policy
Resolve merge conflict Fix files → git add → complete merge/rebase
Run tests php artisan test
Merge After required review/checks
 

 

44. Interview Questions

 

Q1. What is a typical Bitbucket Git workflow?

 

A common workflow is:

 
Clone → Branch → Code → Test → Commit → Push → Pull Request → Review → Merge
 

Q2. Why do developers create feature branches?

 

Feature branches isolate development work from shared branches and allow changes to be reviewed before integration.

 

Q3. What is a Pull Request?

 

A Pull Request is a request to integrate changes from one branch into another while allowing review, discussion, and automated checks according to the team's workflow.

 

Q4. Why should you run git diff before committing?

 

It helps verify exactly what code has changed and reduces the chance of committing unrelated or accidental modifications.

 

Q5. What does git push -u do?

 

It pushes the branch and establishes upstream tracking between the local branch and its remote branch.

 

Q6. How do you update your feature branch with the latest develop changes?

 

A common approach is:

 
git fetch origin
git merge origin/develop
 

A team that uses rebasing may instead use:

 
git fetch origin
git rebase origin/develop
 

Q7. What should you do when a merge conflict occurs?

 

Inspect the conflict with git status, resolve the conflicting files, stage them, complete the merge or rebase, and run the appropriate tests.

 

Q8. Should you commit .env to Bitbucket?

 

Generally, production or developer environment secrets should not be committed. Laravel projects typically use environment-specific configuration outside the repository.

 

Q9. What should you do before creating a Pull Request?

 
  •  
  • Review the changes
  •  
  • Run tests
  •  
  • Check the branch is up to date according to team policy
  •  
  • Review the commit history
  •  
  • Remove unrelated changes
  •  
  • Write a clear Pull Request description
  •  
 

Q10. What is the difference between origin and upstream?

 

They are conventional remote names. In a fork workflow, origin commonly points to your fork and upstream to the original repository.

 

 

45. Easy Way to Remember the Complete Workflow

 
1. CLONE
   ↓
2. UPDATE
   ↓
3. BRANCH
   ↓
4. CODE
   ↓
5. TEST
   ↓
6. COMMIT
   ↓
7. PUSH
   ↓
8. PULL REQUEST
   ↓
9. REVIEW
   ↓
10. FIX FEEDBACK
   ↓
11. APPROVE
   ↓
12. MERGE
   ↓
13. DEPLOY
 

For a PHP/Laravel developer, this workflow becomes second nature with regular practice.

 

 

Conclusion

 

A professional Bitbucket Git workflow is more than knowing commands such as git push and git pull.

 

You need to understand how those commands fit into the complete development lifecycle:

 
Repository
   ↓
Branch
   ↓
Development
   ↓
Commit
   ↓
Push
   ↓
Pull Request
   ↓
Code Review
   ↓
Testing
   ↓
Merge
   ↓
Release
 

For Laravel developers, a good workflow helps keep features isolated, commits understandable, code review manageable, and shared branches stable.

 

The most important principle is:

 
Develop in focused branches, commit meaningful changes, review before merging, and follow the team's repository and deployment policy.
 

 

What's Next?

 

Now that we have covered the complete Bitbucket workflow, the next important topic is one of the most common problems developers face while working with remote branches.

 

Next Article: Git Branch Tracking & Upstream Branch Explained

 

We will cover:

 
  •  
  • What is a tracking branch?
  •  
  • What is an upstream branch?
  •  
  • Local branch vs remote-tracking branch
  •  
  • git branch -vv
  •  
  • git push -u
  •  
  • git branch --set-upstream-to
  •  
  • How git pull knows which remote branch to use
  •  
  • How git push knows where to push
  •  
  • Fixing "no upstream branch" errors
  •  
  • Practical Bitbucket examples
  •  
  • Common Git interview questions
  •  
 

Was this useful?

No ratings yet — yours can be the first.

Discussion

Notes from readers. Comments appear after a short review.

No comments yet. Start the thread below.