Automat-ITip - When you want to migrate your project's code to a new SCM using GIT...




AutomatTip:

When you want to migrate your projects code to new SCM using GIT you can use the next script template,

Read the instructions and change the parameters to yours.

Make sure you have a project ready to get all those repos on your SCM.

Enjoy,

#!/bin/bash 

#############################################################

# Create a folder containing the next structure (2 files and one folder)              

# All the repositories you want to upload to bitbucket sould ne in the 'repo_folder'  

#                                                                                     

# |_ root folder                                                                      

#   |_ .gitignore                                                                     

#   |_ Move_To_Bitbucket.sh                                                           

#     |_ repo_folder                                                                  

#       |_repo_1                                                                      

#       |_repo_2                                                                      

#                                                                                    

#############################################################

username=         [YourAdminUsername]

password=          [YourAdminPassword]

bitbucket_url=    [YourBitbucketURL]/rest/api/1.0/projects/

bitbucket_server= [BitbucketServerHostName]

ssh_port=         [SSHPort]

project_key=      [TargetProjectKey]

repo_folder=      "repo_folder"

echo -e "Target Project is:" $project_key

repos=(`ls $repo_folder | cut -d '.' -f1`) 

read -p "Are you sure? (n/Y) " -n 1 -r 

if [[ ! $REPLY =~ ^[Yy]$ ]] 

then 

    [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1

fi 

for i in "${repos[@]}"

do

    echo "Repo Name:" $i

 curl -u $username:$password -H "Content-Type: application/json" -X POST -d '{"name": "'$i'","scmId": "git","forkable": true}' $bitbucket_url/$project_key/repos -k

 sleep 1

 cp .gitignore $repo_folder//$i #Remark if you don't have .gitignore file

 cd "$repo_folder//$i"

 git init 

 git remote add origin ssh://git@$bitbucket_server:$ssh_port/$project_key/$i

 git checkout -b init

 git add .

 git commit -am "Initial commit"

 git push --set-upstream origin init

 cd ../..

 echo

done


For more DevOps tips, to learn, share, and socialize join Automat-IT DevOps Experts Forum: https://t.me/joinchat/E61TXg-lkaNusP9FdqtxMg

OUR CENTERS OF OPERATIONS & DEVELOPMENT

ISRAEL - SALES & DEVELOPMENT

LABS TLV, 61 Floor

Derech Menachem Begin 121,

Tel Aviv-Yafo, 6701203

+972.79.555.5440

info@automat-it.com

UKRAINE - DEVELOPMENT AND SUPPORT

Serpova str. 4a, office 2

Kharkiv 61000

+380.93.524.4633‬ 

info@automat-it.com

NYC - SALES & OPERATIONS

244 Fifth Avenue

New York, NY 10001

+1.917.841.8014

info@automat-it.com

  • Automat-IT LinkedIn
  • Automat-IT Facebook
  • automat-it twitter
  • Telegram

Let's Talk Today

© 2016-2020 AUTOMAT-IT all rights reserved     |     Privacy Policy