Version control, although commonly used in application development parlance, is relevant for every organization as it relates to change management of documents, computer programs, web pages or any other pool of information. In the application development industry, version control is of utmost importance because it directly affects the core application. In most cases, source code doesn’t remain the same for long as existing functionalities need to be updated or functionality added based on changing demands. Compound this with multiple developers working on the same project. Therefore, it becomes imperative to implement strict version control policies to keep the application development process both streamlined and efficient.
There numerous open source and licensed version control tools available in the market, but a few have become quite popular over time – Subversion (SVN) and Git. SVN was launched around 2000 and has been a widely used source control system since. Git came into existence around 2005 and has been steadily gaining popularity.
As development teams are spread across geographies, using SVN becomes a challenge as users need to be connected to the central SVN repository to commit the code. This is where Git shines due to its distributed source control. Git offers the capacity to manage source code for large open source projects as well as projects with geographically distributed development teams.
With the news of GitHub’s potential acquisition by Microsoft, Git has been pulled into the spotlight. Although it’s early to say, but this acquisition will further drive adoption of Git among developers. In this blog, we look at functionalities that make Git a prominent choice of developers as well as the steps to migrate from SVN to Git. Here are a few benefits of Git over SVN.
Working Offline
With Git, you can work on the go – from anywhere. The centralized Version Control Systems (VCS) of SVN requires connection to the central repository which makes working on the move difficult. But with Git, working on a local machine provides complete flexibility to developers.
Distributed Version Control
Git, unlike SVN, is based on a distributed version control system that works on the principle that each developer has saved the project repository to their hard drive. With SVN, all changes must be directly synched with its central repository as it doesn’t have a local version. In Git, a duplicate version of the project is stored on every developer’s local machine, and the changes are either “pushed” up to the online repository, or “pulled” down from the repository to update the version that the developer has on their machine.
Branching
Branching of SVN is can take considerable amount of disk space as compared to Git. The main difference between Git branching and SVN branching is the amount of space they use. In Git, branches are lightweight. When you create a branch, you are adding a single file of 40 bytes with the branch’s name. You can create as many branches as you like in Git without worries about storage. As compared to SVN, Git offers more flexibility in the way it collaborates. The graph-based model makes it more effective for powerful branching, merging and resolving conflicts.
Steps to migrate from SVN to Git
Thanks to the above benefits, a many organizations are either considering a migration from SVN to Git or have already done so. Below are the steps to follow to ensure the migration is effective and efficient.
A great utility tool called git-svn can be used for the migration. You can download it from https://git-scm.com/docs/git-svn
Git Migration Steps
- First, Extract the list of users who have committed the current SVN repository using the following command:
svn log -q [SVN repo path] | grep -e ‘^r’ | awk ‘BEGIN { FS = “|” } ; { print $2 }’ | sort | uniq > authors.txt
The content of the author’s file would be similar to:
johnlarry
nicolewatson
Now modify the author file as shown below. In this step, add the details required to create users in Git:
johnlarry = John Larry <[email protected]></[email protected]>
nicolewatson = Nicole Watson < [email protected] >
This author file will map the SVN user to Git users so that check-in history can be correctly migrated along with the username.
- Then, the SVN repository is cloned by using the following command (Git SVN clone)
git svn clone –stdlayout –prefix ‘svn/’ -A authors.txt $SVN_PROJECT_PATH
Upon running the above command, a new Git repository will be created for the project. The authors.txt file needs to be provided to remap the users and the project paths on the SVN and the name of the converted project which is optional.
- Now that the projects are converted into the Git repository, the branches can be managed with the following command.
git for -each – ref refs / remotes / svn–format = “%(refname:short)” | sed ‘s#svn/##’ | grep – v ‘^tags’ |
while read aBranch;
do git branch $aBranch svn / $aBranch;
done
The command mentioned below helps list the branches:
git branch -a
- The change tag will be converted as follows:
git for -each – ref refs / remotes / svn / tags–format = “%(refname:short)” | sed ‘s#svn/tags/##’ |
while read aTag;
do git tag $aTag svn / tags / $aTag;
done
The command mentioned below will show the tags list:
git tag
- All the branches and tags are now complete. Next, add the Git repository remote origin to the locally converted repository and then all the code is pushed to the remote repository. The process is outlined below:
git remote add origin GIT_REPOSITORY_URL
git push –all origin
git push –tags origin
Once the repository is successfully migrated, login to the Git repository and check the history and mapping of the users with their commits.
Importance of Git Training
To ensure a widely successful adoption of Git, it is crucial that developers are trained. Developers should be brought together into a group setting and trained on Git and the new workflow. Different components including the differences and similarities between SVN and Git need to be understood (what distributed means in practice, pulling, pushing, committing, adding, stashing its items to the index, etc.). With the proper training and practice, developers will adapt to the Git toolset.
Notes of Consideration
- Migration takes time, i.e. a large repository may take several hours. Try to avoid network delays.
- If GITSVN is used, then the process should be pretty smooth but backups are an important step toward disaster recovery.
- SVN has a built-in permissions system for user accounts. With Git, it’s probably best to use Secure Shell (SSH) keys to restrict access to the Git server to achieve the same security.
Conclusion
Git is a powerful framework for managing version control. Emtec’s team of application development experts has years of experience with Git and related DevOps processes. If you would like to revolutionize your application development organization by implementing DevOps, migration to Git could be the first step. Contact us to get started.