I have been playing around with Git for a while now and its a great tool. The workflow is so much development oriented. So recently I decided to move one of my projects from SVN to Git, actually GitHub to be more specific. This post here details the steps in the process and lists some things to look out for. It assumes a basic understanding of Git. The Official Git Tutorial page is a good place to start. I found this talk by Linus Trovalds very insightful.
1. Register with GitHub
If you want to centrally host you Git repository on a server you can use GitHub. Its an excellent service for Git based projects with lots of features. It allows you to have both public and private hosted repositories.
2. Clone the SVN repository
The first step in the process is to clone the SVN repository to a local Git repository. To do this run the following command
git svn clone -s <SVN Repo URL> <Git Repo Local Dir>
NOTE: Remove the -s option if you don’t have a standard SVN layout (tags, trunks, branches). You might need to use the
Depending on the size of the SVN repository and the commits in it this process might take a long time so go grab a coffee.
3. Check the Git repo
Now that the SVN repository is cloned into a Git repository we can check the files in the new repository. Run the following command to see commit logs. But we did not commit anything yet in Git, right? Well these are commits in SVN which Git has added into the new repository.
4. Add from svn:ignore
If the SVN repository uses svn:ignore to ignore specific files, corresponding .gitignore files can be created as follows
git svn create-ignore
git add .
git commit --message "Committing gitignore files"
If the repository is to be published on a central server then proceed with the next steps otherwise you can jump to the What Next? section.
5. Push the Git repository to GitHub
You now have a local Git repository, ready to be pushed onto the GitHub server. But first things first. Generate a public/private keypair by following either of these guides based on your OS Set Up Git (Windows) and Set Up Git (Linux)
git remote add origin <SSH Git URL>
git push -u origin master
The SSH Git URL can be found by selecting the Git repository in GitHub and looking at the header as shown below
Now you are all set and can start making changes to to your code and using the wonderful features of Git. But before that a few things to remember and understand.
- Git does not track individual files but the contents
- Git cannot have empty folders
- A commit operation in Git commits to the local Git repository not the central repository. If you want to push it to the central repository then use
- Always run
git addbefore doing any commits to ensure that any new files are added. Alternatively you can use the
-aswitch in Git commit along with the
- Use branches whenever making changes. Its way too easy and a very central feature of Git.
git stashto store your changes into a working directory in case you need to restore to another branch temporarily.