logo
eng-flag

Bitbucket Cheatsheet

Table of Contents

  1. Introduction to Bitbucket
  2. Setting Up Bitbucket
  3. Basic Git Commands
  4. Branching and Merging
  5. Pull Requests
  6. Issue Tracking
  7. Bitbucket Pipelines
  8. Bitbucket API
  9. Advanced Features
  10. Best Practices

Introduction to Bitbucket

Bitbucket is a web-based version control repository hosting service owned by Atlassian, primarily used for source code and development projects that use Git revision control systems.

Key Features:

  • Free unlimited private repositories
  • Integrates with Jira and other Atlassian products
  • Built-in CI/CD with Bitbucket Pipelines
  • Pull requests and code review
  • Issue tracking
  • Wiki for documentation

Setting Up Bitbucket

  1. Create an Account: Visit bitbucket.org and sign up for a new account.

  2. Create a New Repository:

    • Click on the '+' icon in the sidebar
    • Select 'Repository'
    • Choose a name, set it to private or public
    • Select Git as the version control system
    • Click 'Create repository'
  3. Clone the Repository:

    git clone https://yourusername@bitbucket.org/yourusername/your-repo.git
    
  4. Set Up SSH Key (Optional but Recommended):

    • Generate SSH key:
      ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
      
    • Add the public key to your Bitbucket account settings

Basic Git Commands

  1. Add Files:

    git add filename
    git add .  # Adds all files
    
  2. Commit Changes:

    git commit -m "Your commit message"
    
  3. Push Changes:

    git push origin main
    
  4. Pull Changes:

    git pull origin main
    
  5. Check Status:

    git status
    
  6. View Commit History:

    git log
    

Branching and Merging

  1. Create a New Branch:

    git branch new-feature
    git checkout -b new-feature  # Creates and switches to the new branch
    
  2. Switch Branches:

    git checkout branch-name
    
  3. Merge Branches:

    git checkout main
    git merge new-feature
    
  4. Delete a Branch:

    git branch -d branch-name  # Local deletion
    git push origin --delete branch-name  # Remote deletion
    

Pull Requests

  1. Create a Pull Request:

    • Push your branch to Bitbucket
    • Go to your repository on Bitbucket
    • Click 'Create pull request'
    • Select source and destination branches
    • Add title and description
    • Click 'Create pull request'
  2. Review a Pull Request:

    • Go to 'Pull requests' in your repository
    • Click on the pull request you want to review
    • Add comments, approve, or request changes
  3. Merge a Pull Request:

    • After approval, click 'Merge'
    • Choose merge strategy (merge commit, squash, fast-forward)
    • Confirm the merge

Issue Tracking

  1. Create an Issue:

    • Go to 'Issues' in your repository
    • Click 'Create issue'
    • Add title, description, assignee, and labels
    • Click 'Create issue'
  2. Manage Issues:

    • Filter issues by status, assignee, or label
    • Comment on issues for updates
    • Close issues when resolved
  3. Link Issues to Commits: In your commit message, reference the issue:

    git commit -m "Fix login bug (fixes #123)"
    

Bitbucket Pipelines

  1. Enable Pipelines:

    • Go to repository settings
    • Click on 'Pipelines' and enable
  2. Create bitbucket-pipelines.yml:

    pipelines:
      default:
        - step:
            name: Build and Test
            script:
              - npm install
              - npm test
    
  3. View Pipeline Results:

    • Go to 'Pipelines' in your repository
    • Click on a pipeline to see details and logs

Bitbucket API

  1. Authentication: Use App passwords or OAuth for API authentication

  2. Example API Request (Using curl):

    curl -u username:app_password -X GET https://api.bitbucket.org/2.0/repositories/username/repo_slug
    
  3. Webhook Setup:

    • Go to repository settings
    • Click on 'Webhooks' and add a new webhook
    • Specify URL and triggers

Advanced Features

  1. Snippets: Share code snippets with your team

  2. Forks: Create a copy of a repository to propose changes

  3. Bitbucket Cloud vs Server: Choose between cloud-hosted and self-hosted options

  4. Integrations: Connect with tools like Jira, Trello, and Slack

Best Practices

  1. Use Meaningful Commit Messages:

    git commit -m "Add user authentication feature"
    
  2. Regular Pulls and Pushes: Keep your local repository up-to-date and push changes frequently

  3. Branch Naming Conventions: Use prefixes like feature/, bugfix/, hotfix/

  4. Code Review: Always have at least one reviewer for pull requests

  5. Keep Repositories Clean: Use .gitignore to exclude unnecessary files

  6. Use Tags for Releases:

    git tag -a v1.0 -m "Version 1.0 release"
    git push origin v1.0
    
  7. Backup Your Repositories: Regularly clone or mirror your repositories for backup

2024 © All rights reserved - buraxta.com