如何克隆一个Bitbucket代码库?

33

休息一段时间后回来工作,我似乎不知道如何克隆一个Bitbucket存储库。有什么想法为什么会出现“未找到”错误?

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

系统:

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

2
前往您想要克隆的Bitbucket存储库,在左侧窗格中,有一个“克隆”选项。单击它将为您提供存储库的链接。复制它并尝试“git clone url-from-bitbucket”。这应该可以工作! - Sajib Acharya
1
@SajibAcharya,对不起,没有“克隆”选项。我能找到的唯一网址是“https://bitbucket.org/helllamer/mod_openid”。如果你找到了其他的,请告诉我。 - The user with no hat
你从哪里得到这个URL的?当我点击它时,它显示404错误。此外,Bitbucket克隆URL看起来不像你发布的那个。它看起来有点像https://username@bitbucket/path/to/project。你确定你正在使用正确的URL吗? - Sajib Acharya
此外,如果它是一个git仓库,它应该以.git结尾。你的URL格式不正确。 - Sajib Acharya
1
还有一些人会在不给出任何具体原因的情况下对一个问题进行负评 -_- - Sajib Acharya
显示剩余2条评论
8个回答

31

在 Bitbucket 屏幕左侧有一个带有按钮的垂直列。从顶部数第二个按钮是 "CLONE" 按钮。 点击这个按钮。您将获得 HTTP 地址。 在此输入图像描述

复制该地址并按照常规方式在 git 中使用:

git clone <仓库的 HTTP 地址>


10
Bitbucket的想法是:把它藏在人们不容易找到的地方。 - Reza

25

2
谢谢@Chris!我刚刚几秒钟前发现了这个...值得一提的是UI并不是很有帮助。 - The user with no hat
1
同意!我也花了几分钟才弄明白。 - Chris
在更大的屏幕上,它会提供一个完整的描述性侧边栏,而不像在小屏幕的浏览器中那样。 - Sajib Acharya
1
@SajibAcharya,我向你保证我正在使用一个非常大的屏幕。侧面板似乎没有包含有关此存储库使用哪个版本控制系统的任何信息。我唯一看到它的地方是作为SSH克隆URL的一部分。 - Chris
2
@SajibAcharya,在那个截图中,你看到了我们正在处理一个Mercurial仓库的迹象吗? - Chris
显示剩余2条评论

3

使用 HTTPS 克隆仓库时,您需要首先生成一个访问令牌(不能再使用登录密码),然后使用该令牌克隆仓库。

生成访问令牌:

个人设置 > 应用程序密码 > 创建应用程序密码

克隆仓库:

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

它会提示您生成令牌。

1

这很简单,与GitHub相同。 从浏览器进入Bitbucket存储库并复制URL。 在所需位置打开终端,即要克隆存储库的位置,然后键入以下内容:

git clone <copied url of repo.>

然后它会要求您输入Bitbucket用户名和密码。提供后,您可以进行克隆。


0
#!/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

0
很可能这是一个私有仓库,你有访问权限而我没有。你需要做的是将鼠标移动到左侧窗格顶部的三个点上(参见图像),然后会弹出一个窗口,在其中你会找到克隆选项。点击它,你会得到一个命令,如hg clone bitbucket-url(正如Chris所提到的,这是一个Mercurial仓库)。复制它并粘贴到你的终端上。如果你有访问该仓库的权限,你就能够克隆它了。

0

如果你不是命令行类型的人,最好的方法就是下载Sourcetree或使用Mercurial进行克隆。


0
以下对我在Mercurial存储库中有效。
hg clone https://[YourUserName]@bitbucket.org/tr_radlab/radlab-for-windows/branch/default

在上面的URL中,将[YourUserName]替换为您的用户名。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接