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

Let's Talk

ISRAEL - SALES & DEVELOPMENT

Aluf Kalman Magen St 3

Tel Aviv-Yafo, 6107075

+972.79.555.5440

info@goeaas.com

NYC - SALES & OPERATIONS

244 Fifth Avenue

New York, NY 10001

+1.917.841.8014

info@goeaas.com

UKRAINE - DEVELOPMENT AND SUPPORT

Serpova str. 4a, office 2

Kharkiv 61000

+380.93.524.4633‬ 

info@goeaas.com

CALIFORNIA - SALES & OPERATIONS

Valley Towers
75 E Santa Clara St.

San Jose, CA 95113

info@goeaas.com

+1.917.841.8014

  • Go EaaS LinkedIn
  • Go EaaS Facebook
  • automat-it twitter
  • Telegram

© 2018-2020 Go EaaS all rights reserved     |     Privacy Policy