SVN to GIT/Bitbucket Migration Steps
Please follow below steps to perform SVN to GIT/Bitbucket migration:
Prerequisites:
1. Must have a RHEL-7 or higher Linux server available to perform the steps.
2. The location where you decide to create new directory as “git_migration” must have enough disk space to hold the final GIT repository. Check the actual source SVN repo size
/root/git_migration
3. Must have installed these software/tools in server Min. JDK-8, SVN and GIT client
Installation commands, if you have access to internet from Linux server and subscription is in place:
yum install subversion
yum install git
yum install git-svn
4. Its assumes that your SVN repo uses standard directory convention as trunk/tag/branches
5. You must have a Bitbucket/Git account created and new repository as “mygit” is ready to add a new repo code base.
Atlassian scripts to download for basic sanity on prerequisite environment is proper or not:
https://bitbucket.org/atlassian/svn-migration-scripts/downloads/
https://bitbucket.org/atlassian/svn-migration-scripts/src/master/
Verify that all necessary tools are installed
java -jar svn-migration-scripts.jar verify
e.g. output will show like below
[root@hostname]# java -jar svn-migration-scripts.jar verify
svn-migration-scripts: using version 0.1.56bbc7f
Git: using version 2.31.1
Subversion: using version 1.10.2
git-svn: using version 2.31.1
Preparation steps:
- Create new blank repository in your GitHub account "svn_git_migration"
- On new VM perform below steps to prepare authors file which will needed for history revision number and author name.
- java -jar svn-migration-scripts.jar authors <Your SVN Repo URL> <user_name> <Password> e.g. java -jar svn-migration-scripts.jar authors https://mysvn.com/svn/REPO ram_krishna Pasword123
- Will get output as below and create new authors.txt file and change name as per git user naming convention user_name = user_name <user_name@mycompany.com>
- Create local Git repository from SVN repo. Run below command.
- nohup git svn clone --no-metadata -A /root/git_migration/authors.txt https://mysvn.com/svn/REPO --trunk=trunk --tags=Tags --branches=Branches --username=user_name > svn_git_migration.out &
- This command will run in background and take time based on your SVN repository size.
- You can verify the output in tail mode as $ tail -1000f svn_git_migration.out
Once above process gets successfully completed then you can verify by running below commands
1. Can see all the branches are migrated from SVN to local git repository.
$ git branch -a
master
trunk
my_branch
** Now based on your requirement you can start push the code into your remote git branch.
Before this make sure below global configuration of git is already updated and SSH key setup done on git profile setting to push the code.
$ git config --list --show-origin
$ ssh -T git@github.com
> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.
Check whether ssh agent is running or not, It will give u PID
$ eval "$(ssh-agent -s)"
Generate ssh key from gitbash or command prompt:
$ ssh-keygen -t rsa -b 4096 -C "Ur_Email_ID"
You can refer below articles if you faced any issues during initial setup:
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
Generating a new SSH key and adding it to the ssh-agent - GitHub Docs // Adding a new SSH key to your GitHub account - GitHub Docs
https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
2. Finally you can checkout the respective branch and push the code into remote git repo
$ git remote add origin https://github.com/demo/mygit.git
$ git checkout -b trunk origin/trunk
$ git push origin origin/trunk
3. You can login to GitHub portal and cross check whether push code is present or not.
That's it, If branch is visible in GitHub then you have successfully migrated repository from SVN to GIT.
Splitting Your Git Repo While Maintaining Commit History:
Lets say this is the base git repo which contain your UI and API code base as below
Existing repository with combined code base directory:
https://github.com/demo/AllCode.git
---FrontEnd/
---BackEnd/
Create two new repository as FrontEnd_UI and BackEnd_API
https://github.com/demo/FrontEnd_UI.git
https://github.com/demo/BackEnd_API.git
Perform below steps one by one:
You can change here branch as per your setup, here used trunk branch
Set-1] UI
git clone -b trunk https://github.com/demo/AllCode.git
cd <Folder>
git filter-branch --prune-empty --subdirectory-filter FrontEnd/ -- trunk
git remote remove origin
git remote add origin https://github.com/demo/FrontEnd_UI.git
git push --all
git push --tags
Set-2] API
git clone -b trunk https://github.com/demo/AllCode.git
cd <Folder>
git filter-branch --prune-empty --subdirectory-filter BackEnd/ -- trunk
git remote remove origin
git remote add origin https://github.com/demo/BackEnd_API.git
git push --all
git push --tags
Comments
Post a Comment