How to construct ‘git clone’ command to clone only a specific tag or a branch in a repository
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
Customers encounter access errors while cloning a repo or branch
1
git@bitbucket.org: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Cause
Using incorrect URLs either to clone the repo or a specific branch
Example:
URL: git clone ssh://git@altssh.bitbucket.org:443/<workspace_ID>/<Repository_SLUG>@v3.3.1
Solution
Below are the commands to clone repo/branch/tag without experiencing permission denied errors
Command to clone a repository :
1
git clone https://<User_Name>@bitbucket.org/<Workspace_ID>/<Repo_Name>.git
Command to clone a branch :
1
git clone https://<User_Name>@bitbucket.org/<Workspace_ID>/<Repo_Name>.git --branch <branch_name>
Command to clone a tag :
1
git clone https://<User_Name>@bitbucket.org/<Workspace_ID>/<Repo_Name>.git --branch <tag_name>
In order to clone the history of the branch or tip of a tag we can use “--single-branch“ option
Example:
1
git clone https://<User_Name>@bitbucket.org/<Workspace_ID>/<Repo_Name>.git --branch <branch_name> --single-branch
1
git clone https://<User_Name>@bitbucket.org/<Workspace_ID>/<Repo_Name>.git --branch <tag_name> –single-branch
Updated on April 8, 2025
Was this helpful?
Still need help?
The Atlassian Community is here for you.