As we were forced to move our GIT repositories from a cloud hosting service to our servers on site I wrote a litte shellscript for OSX to do this for me repository by repository.
The main problem was to transfer the LFS content wich wasn’t supported by our cloud hosting service so we had to check out everything and push it to the new hoster. This came with new problems like transferring all branches and tags.
But luckily there is an answer for everything which i’d like to share if someone runns into similar problems!
First of i request the projectname (reponame) and the old and new git repo url. I did this with ssh but https auth should work aswell
#!/bin/sh read -p "Enter project name to Clone: " projectname read -p "Enter old Git URL(ssh): " oldgiturl read -p "Enter NEW Git URL(ssh): " newgiturl
Then i ran git clone with the mirror argument to completely copy the repo with all branches.
git clone –mirror –recurse-submodules $oldgiturl
git config –bool core.bare false
git lfs fetch --all origin
After checking everything out you can download the LFS content
git remote add new-origin $newgiturl git push -u new-origin --all git push --tags new-origin git lfs push --all new-origin
After this you add a new origin and push everything to it.
Repeat for every repository you want to move.
If you have submodules in your projects like me, you can alter the script and have them mapped to the new hoster as well.
Luckily for me we have always the same project layout so checking the submodules was easy.
[ -d "Assets/Submodules/base_loca" ] && git rm -rf /Assets/Submodules/base_loca && git submodule add --name base_loca **insertnewhosterurlhere**/base_loca.git Assets/Submodules/base_loca
Here i checked if the submodule exists in the downloaded content, if so, i remove it and add the corresponding submodule which was already transferred beforhand. These submodule repacement lines of code has to be repeated for every submodule you have and are hardcoded in the script.
Maybe this can be done more efficient but it worked for us.
I hope this helps you to do this kind of monkey job a bit faster 😉