For those who are following my posts and my open source work, might have found that I've started adopting GitHub for KonfDB and my blog samples. So I thought of moving my open source tools from CodePlex to GitHub so that I can centralize my code. So here I go with what anybody would do – Google.
To my amusement, there are some posts that suggest using GitHub import wizard which looked quite easy to believe. But one of the bigger problem is that the import wizard does not allow providing user name and password. So for protected svn repositories, the GitHub import wizard does not work.
Another solution was to take the latest from CodePlex (SVN) and then check-in the code in GitHub. But that would mean letting go of the check-in history. So I needed something even more automated.
Procuring the tools – Ruby
You can get the latest version of Ruby Installer and install Ruby on your machine. This is because the tool we are going to use to migrate SVN to GitHub (svn2git) is built using Ruby and we need Ruby in the executable PATH.
Enabling Trust with RubyGems
Ruby uses RubyGems as Package Manager and apparently it uses HTTPS url to get the packages. On Windows, I was prompted with following error
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://api.rubygems.org/specs.4.8.gz)
I found the solution to this problem on StackOverflow – the summary of which is
Find out the directory for RubyGems by the command shown below
Download PEM file from https://raw.githubusercontent.com/rubygems/rubygems/master/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem and copy it to
This should allow you to download packages from gem.
To download svn2git, execute following command
gem install svn2git
The output of this command will be like,
Accessing CodePlex SVN repository
To get the SVN repository details, we can access the CodePlex repository > Source tab and click on Connect icon
Copy the SVN URL and execute these steps as shown below in a directory that is empty.
Downloading the code with history into Local Git Repository
svn2git https://codeinject.svn.codeplex.com/svn/ -v --username PuneetGhanshani --nobranches --notags --rootistrunk
Substitute the SVN url in the above command and default username and execute it on a Command Prompt
When accessing SVN repository, it will prompt you to accept Microsoft CodePlex certificate. You can accept it temporarily or permanently.
The output of this operation will look something like
Running command: git svn init --prefix=svn/ --username=PuneetGhanshani --no-metadata --trunk=https://codeinject.svn.codeplex.com/svn/ Running command: git svn fetch Running command: git branch -l --no-color * master Running command: git branch -r --no-color svn/trunk Running command: git config --local --get user.name Running command: git config --local --get user.name Running command: git config --local --get user.email Running command: git checkout -f master Already on 'master' Running command: git gc
If you are going to use this code locally, you don't need to proceed ahead with this article. But if you are looking at uploading this code with history to a public Git repository like GitHub or BitBucket, you can follow the next step
Upload this Local Git Repository to GitHub
So first you need a target GitHub Repository. You can choose 2 ways to perform this operation.
Using GitHub Website and Git in Console
Once you have created a GitHub Repository, you can copy the HTTPS URL which will appear like,
Next you need to configure local Git session to use this as remote URL
git remote add origin https://github.com/PuneetGhanshani/TestRepository.git
You can verify if this worked fine as shown in the screenshot below
Once this is done, a single command to push
git push –-all
This will push all the code from local Git to GitHub repository – includes history as well. If you have added some files manually to GitHub repository (like readme.md and .gitignore), you need to first update your local Git repository from GitHub repository using command
If you even after updating local Git repository, you get an error like
! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/PuneetGhanshani/TestRepository.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
You can edit the .git\config file and add these 2 lines at the end of file and request a pull again.
[branch "master"] remote = origin merge = refs/heads/master
This should definitely resolve this error
Using GitHub for Windows
GitHub for Windows actually makes this quite easy for you.
First, click on the Options menu and update the path where you have got your local Git repository. Once you have updated it, you can scan for repositories.
If the repository is local, GitHub for Windows will allow you to Publish the repository to GitHub