Last active
February 16, 2018 22:31
-
-
Save alexandremucci/a40d668f3e7fdd033a0262ab15e16d57 to your computer and use it in GitHub Desktop.
Script to create and clone Bitbucket repository (using Bitbucket REST API)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# set username | |
username="username" | |
# set password to use REST API | |
# If you have two-step verification enabled (which is recommended), set an app password with restricted permissions (admin for repositories) an use it here. | |
# To other restricted actions below (clone and push) you will be asked to provide your password or ssh key. | |
# You can also change these lines (clone and push) and use the same password defined here, but be aware of security concerns about storing passwords in plain text. | |
password="password" | |
# enter repository name | |
echo -n "Enter the project name:" | |
read -e repository | |
# check if you already have a folder with this name | |
if [ ! -d $repository ] | |
then | |
# create bitbucket repository | |
# version control: git | |
# access level: private | |
# fork policy: no forks | |
curl -X POST -v -u $username:$password -H "Content-Type: application/json" https://api.bitbucket.org/2.0/repositories/$username/$repository -d '{"scm": "git", "is_private": "true", "fork_policy": "no_forks" }' | |
# clone remote repository | |
git clone [email protected]:$username/$repository.git | |
# go to local folder | |
cd $repository | |
# create README file if it doesn't exists | |
if [ ! -f README.md ] | |
then | |
# create readme file | |
echo "#Project: $repository" >> README.md | |
# add readme to git | |
git add README.md | |
# initial commit | |
git commit -m "Initial commit" | |
# push readme to origin | |
git push -u origin master | |
fi | |
else | |
echo "Folder already exists." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment