简体   繁体   中英

How to clone a bitbucket repository?

Getting back to work after a while it seems I don't know how to clone a bitbucket repository. Any idea why I get the "not found" error?

git clone --verbose https://bitbucket.org/helllamer/mod_openid
Cloning into 'mod_openid'...
remote: Not Found
fatal: repository 'https://bitbucket.org/helllamer/mod_openid/' not found

System:

git version 1.9.1
uname -a Linux openvpnas2 3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

On the left side of bitbucket screen there is a vertical column with buttons. The second button from the top is "CLONE" button . Press on this button .You will get HTTP address . 在此处输入图像描述

Copy this address and use in git in regular way :

git clone <HTTP address of repo>

This is a Mercurial repository, not a Git repository. Bitbucket supports both systems .

Clone with:

hg clone https://bitbucket.org/helllamer/mod_openid

For more information about Mercurial please see its Wikipedia page .

It is simple and same as in GitHub. Go to Bitbucket repository from your browser and copy url. Open a terminal in desired location, where you want to clone the repository, and then type this:

git clone <copied url of repo.>

Then it ask your Bitbucket username and password. After providing them, you can clone it.

Most probably it is a private repository where you have access permissions and I do not. What you need to do is move your mouse on the three dots on the left pane at the top (refer the image) and then you'd get a pop up where you'd find the clone option. Click on that and you'd get a command like hg clone bitbucket-url (It is a Mercurial repository as mentioned by Chris). Copy that and paste it on your terminal. You'll be able to clone that if you have permissions to access the repository.

The following works for me for Mercurial repository.

hg clone https://[YourUserName]@bitbucket.org/tr_radlab/radlab-for-windows/branch/default

Put your user name in place of [YourUserName] in above Url.

充其量你只需要简单地下载,如果你不是 cmd 类型,你可以使用 sourcetree 或使用 Mercurial 来享受克隆。

To clone a repository with HTTPS , first you should generate an access token (you can't use your login password anymore) and then clone the repository with this generated token.

Generate access token:

Personal settings > App passwords > create app password

Clone the repository:

git clone https://YOUR-USERNAME@bitbucket.org/YOUR-REPOSITORY

It will prompt you for generated token.

#!/bin/bash

# Set your Bitbucket username and password
BITBUCKET_USERNAME='<<your username>>'
BITBUCKET_APP_PASSWORD='<<your password>>'

# Set the user or team name whose repositories you want to clone
TEAM_NAME='<<team name>>'
LIMIT=50

# Generate a timestamp in the format YYYY-MM-DD
timestamp=$(date +%Y%m%d%H%M%S)

# Get the current date in the format YYYY-MM-DD
DATE=$(date +%F)

# Create a backup directory with the current date and proper permissions
BACKUP_DIR="backup_$DATE"
mkdir $BACKUP_DIR
chmod 700 $BACKUP_DIR

while true; do
  # Use the Bitbucket API to get a list of repositories for the specified team, for the current page
  REPOS=$(curl -u "$BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD" -X GET "https://api.bitbucket.org/2.0/repositories/$TEAM_NAME?pagelen=$LIMIT&page=$PAGE_NUM")

  # Exit the loop if no repositories are returned
  if [[ "$REPOS" == *"\"values\":[]"* ]]; then
    break
  fi

  # Parse the JSON to extract the repository slugs
  REPOS=$(echo "$REPOS" | jq -r '.values[].slug')

  # Clone each repository
  for REPO in $REPOS; do
    git clone "https://$BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD@bitbucket.org/$TEAM_NAME/$REPO.git"  $BACKUP_DIR/$REPO
  done

  # Increment the page number
  PAGE_NUM=$((PAGE_NUM+1))
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM