Skip to content

Instantly share code, notes, and snippets.

@iozozturk
Created August 3, 2017 11:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iozozturk/449b36c910ee28fb2a6e31a05a63b0e5 to your computer and use it in GitHub Desktop.
Save iozozturk/449b36c910ee28fb2a6e31a05a63b0e5 to your computer and use it in GitHub Desktop.
Migration script from any git server to Bitbucket cloud
#declare list of repositories
#clone repositories from list
# git config --global push.followTags true
repos=( repo1, repo2, anyRepo )
function migrate(){
echo "Migrating repos"
currentDir=$(pwd)
for repo in "${repos[@]}"
do
cloneOldRepo $repo
cd $repo
trackAllRemoteBranches
fetchTags
createNewRepo $repo GWT
changeRemoteUrl $repo
pushChangesToNewRepo
cd $currentDir
done
echo "Migration finish"
}
#Create new repos
function createNewRepo() {
echo "Creating new repo:$1 on team $2"
curl -X POST -v -u ismet.ozozturk@sony.com:password "https://api.bitbucket.org/2.0/repositories/teamName/$1" -H "Content-Type: application/json" -d '{"has_wiki": true, "is_private": true, "project": {"key":"'"$2"'"}}'
}
function changeRemoteUrl(){
cwd=$(pwd)
echo "Setting repo:$1 origin adress, currentDir:$cwd"
git remote rm origin
git remote add origin "https://trozozti:password@bitbucket.org/teamName/$1.git"
}
function pushChangesToNewRepo(){
echo "Pushing branches and tags"
git push -u origin --all
}
function fetchTags(){
git fetch –-tags
}
#Track all remote branches
function trackAllRemoteBranches(){
for remote in `git branch -r | grep -v /HEAD`; do git checkout --track $remote ; done
}
#Clone old repos (repoName)
function cloneOldRepo() {
gitBaseURL=http://trozozti:password@gwtgit.sony-europe.com/scm/GWTCDS/
repoUrl=$gitBaseURL$1.git
echo Cloning repo:$repo with url: $repoUrl
git clone ${repoUrl}
echo Finished cloning all repos
}
migrate
@mwingle
Copy link

mwingle commented Jul 30, 2021

Thanks so much! This was a great timesaver!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment