Using Bitbucket Private Repositories
This guide will walk you through the process of using private Bitbucket repositories as templates with gitit.
Prerequisites
Before you begin, you'll need:
- A Bitbucket account with access to private repositories
- A Bitbucket App Password with appropriate permissions
- gitit installed on your system
Creating a Bitbucket App Password
Bitbucket uses App Passwords for API authentication. To create one:
- Log in to your Bitbucket account
- Click on your profile icon in the bottom left corner
- Select Personal settings from the menu
- In the left sidebar, click on App passwords
- Click the Create app password button
- Give your app password a descriptive name (e.g., "gitit Access")
- Select the following permissions:
- Repository: Read
- Pull requests: Read (optional)
- Click Create
- Important: Copy your app password immediately. You won't be able to see it again!
Cloning a Private Repository
Once you have your app password, you can use it to clone private repositories:
gitit bitbucket:username/private-repo my-project --auth "your-app-password"
Replace:
username
with your Bitbucket username or workspace nameprivate-repo
with your private repository nameyour-app-password
with the app password you created
Using Environment Variables
For security and convenience, you can set your app password as an environment variable:
export GITIT_AUTH="your-app-password"
gitit bitbucket:username/private-repo my-project
Add this to your .bashrc
, .zshrc
, or equivalent shell configuration file for persistent access.
Authentication Format for Bitbucket
Unlike GitHub and GitLab which use Bearer tokens, Bitbucket uses the app password as is. The token is added to the HTTP request headers:
Authorization: Bearer your-app-password
Troubleshooting
"Not found" or "404" errors
If you get "Not found" or "404" errors when trying to clone a private repository, check:
- Repository name is correct: Double-check the repository name and username/workspace
- App password has proper permissions: Ensure you've given it "Repository: Read" permissions
- Access to the repository: Confirm that your Bitbucket account has access to the repository
"Authentication failed" errors
If you get authentication errors:
- App password is correct: Make sure you're using the correct app password
- App password is valid: App passwords might expire; generate a new one if needed
- Format is correct: Use the app password as-is without any additional prefixes
Advanced Usage
Specifying Branches
To clone a specific branch from a private Bitbucket repository:
gitit bitbucket:username/private-repo#develop my-project --auth "your-app-password"
Cloning Subdirectories
To clone only a specific subdirectory from a private repository:
gitit bitbucket:username/private-repo/path/to/directory my-project --auth "your-app-password"
Combined Branch and Subdirectory
You can specify both a branch and a subdirectory:
gitit bitbucket:username/private-repo/path/to/directory#develop my-project --auth "your-app-password"
Configuration File
You can store your Bitbucket authentication in your gitit.config.ts
file:
// gitit.config.ts
export default {
auth: process.env.GITIT_AUTH || 'your-app-password',
// other options...
}
Just be careful not to commit this file to version control if it contains your actual app password.
CI/CD Integration
For CI/CD pipelines, use secrets to store your app password:
# GitHub Actions example
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Clone Bitbucket template
run: gitit bitbucket:username/private-repo my-project
env:
GITIT_AUTH: ${{ secrets.BITBUCKET_APP_PASSWORD }}
Best Practices
- Use environment variables: Avoid putting your app password directly in commands
- Use specific branches or tags: Reference specific versions for consistency
- Limit app password scope: Only grant the minimum permissions needed
- Rotate app passwords: Regularly update your app passwords for security
- Consider workspace permissions: Be aware of team access controls in workspaces