Copy a Bitbucket Repository from one account to another bitbucket account
Categories:
How to Copy a Bitbucket Repository to Another Account

Learn the essential steps to securely and efficiently transfer a Bitbucket repository from one account to another, covering both direct cloning and mirroring methods.
Transferring a Git repository between different Bitbucket accounts is a common task for developers, whether it's for organizational changes, personal projects, or collaboration. While Bitbucket offers direct repository transfer within the same workspace, moving a repository to an entirely different account (e.g., from your personal account to a company account, or between two distinct company accounts) requires a few manual steps. This guide will walk you through the process using standard Git commands, ensuring your commit history and branches are preserved.
Understanding the Transfer Process
When you 'copy' a Bitbucket repository, you're essentially creating a new repository in the target account and then pushing all the content, including the full commit history, branches, and tags, from the source repository to the new one. This process typically involves cloning the source repository to your local machine and then pushing it to the newly created, empty repository in the destination Bitbucket account. We'll explore two primary methods: direct cloning and mirroring.
flowchart TD A[Source Bitbucket Repo] --> B{Clone to Local} B --> C[Local Git Repo] C --> D{Create New Bitbucket Repo} D --> E[Target Bitbucket Repo] C --> F{Add New Remote} F --> E C --> G{Push All Content} G --> E
Workflow for transferring a Bitbucket repository between accounts.
Method 1: Standard Clone and Push
This method is straightforward and suitable for most scenarios. It involves cloning the source repository, creating a new empty repository in the target Bitbucket account, and then pushing your local clone to the new remote.
1. Step 1: Create a New Repository in the Target Account
Log in to the Bitbucket account where you want the repository to reside. Create a new, empty repository. Do not initialize it with a README or .gitignore, as this can complicate the initial push. Make sure to note down its Git URL (e.g., https://bitbucket.org/target_user/new-repo.git
).
2. Step 2: Clone the Source Repository
Open your terminal or Git Bash. Navigate to the directory where you want to clone the repository. Use the git clone
command with the URL of the source Bitbucket repository. This will create a local copy of the repository, including all branches and commit history.
3. Step 3: Add the New Remote
Navigate into the newly cloned local repository directory. Now, you need to add a new remote pointing to your newly created empty repository in the target Bitbucket account. We'll call this remote target
.
4. Step 4: Push All Content to the New Remote
Finally, push all branches and tags from your local repository to the target
remote. The --all
flag pushes all branches, and --tags
pushes all tags. You will be prompted for your credentials for the target Bitbucket account.
# Step 2: Clone the source repository
git clone https://bitbucket.org/source_user/old-repo.git
# Navigate into the cloned directory
cd old-repo
# Step 3: Add the new remote
git remote add target https://bitbucket.org/target_user/new-repo.git
# Step 4: Push all content to the new remote
git push --all target
git push --tags target
Git commands for cloning and pushing to a new Bitbucket remote.
target
remote from your local repository using git remote remove target
if you no longer need it.Method 2: Mirroring a Repository
Mirroring is a more robust way to copy a repository, especially useful for ensuring that all references, including remote-tracking branches and other Git metadata, are perfectly replicated. This method creates a 'bare' clone, which is a repository without a working directory, making it ideal for server-side operations or exact copies.
1. Step 1: Create a New Repository in the Target Account
Similar to the first method, create a new, empty repository in the target Bitbucket account. Do not initialize it with a README or .gitignore. Note its Git URL.
2. Step 2: Create a Bare Mirror Clone of the Source Repository
Use the git clone --mirror
command. This creates a bare repository (e.g., old-repo.git
) that is a mirror of the source, meaning it includes all branches, tags, and remote-tracking branches.
3. Step 3: Push the Mirror to the New Remote
Navigate into the bare repository. Then, use git push --mirror
to push everything from this bare clone to the new target repository. This command ensures that all refs (branches, tags, etc.) are mirrored exactly.
# Step 2: Create a bare mirror clone of the source repository
git clone --mirror https://bitbucket.org/source_user/old-repo.git
# Navigate into the bare repository directory
cd old-repo.git
# Step 3: Push the mirror to the new remote
git push --mirror https://bitbucket.org/target_user/new-repo.git
Git commands for mirroring a repository to a new Bitbucket remote.
--mirror
option is powerful and should be used with caution. It overwrites the remote repository's history to exactly match the local mirror. Ensure the target repository is empty or that you intend to completely replace its content.Both methods effectively copy your Bitbucket repository from one account to another while preserving its history. The mirroring method is generally preferred for a complete and exact replication, especially if you're concerned about all Git references. Always double-check the new repository in Bitbucket to confirm that all expected content has been transferred successfully.