Last Updated: February 25, 2016
·
838
· drrobotnik

Interactively create and clone fresh BitBucket Repo

Create a .sh file, mine's called bbclone.sh

#!/bin/bash

ORIGDIR=$(pwd)

cd "$ORIGDIR"
echo "Working in $ORIGDIR"

echo "Project Name:"
read -e PROJECT_NAME

PREP_SLUG=${PROJECT_NAME//[^a-zA-Z0-9\-]/-}
PROJECT_FOLDER=$(echo ${PREP_SLUG} | tr '[A-Z]' '[a-z]')

HTTPDOCS="$ORIGDIR/$PROJECT_FOLDER"

echo "Owner (Leave blank if not team): "
read -e BB_Owner

echo "Username: "
read -e BB_USER

echo "Password: "
read -s BB_PASS

curl -u$BB_USER:$BB_PASS -X POST https://api.bitbucket.org/1.0/repositories/ -d "name=$PROJECT_NAME" -d "owner=$BB_Owner" -d 'is_private=1' -d 'scm=git'

git clone git@bitbucket.org:$BB_Owner/$PROJECT_FOLDER.git $HTTPDOCS

from terminal within the directory you want the new project repo run:

$ sh <PATH_TO_BBCLONE>/bbclone.sh

or create an alias in your bashconfig file.

alias bbclone='<PATHTOBBCLONE>/bbclone.sh'

and follow your interactive instructions.

1 Response
Add your response

nice and useful!

over 1 year ago ·