Transition from SVN to Git - Commands

January 11
blog author



Git is something completely new to me. Coming from SVN, the concepts and commands seemed really different from what I'm used to; SVN checkout, update, add, commit. For SVN, you basically need to know, checkout, update, add and commit. There's a lot more of course, but these 4 commands would get you going. It's just a 2-way connection from your computer and the repository. I found myself completely confused when I started using Git. First, I knew I needed to get the repo from the git: URL. Okay, Git has checkout, so I thought I would try it out (this is me not reading documentation carefully). So after asking some questions and actually reading, I found that 'clone' is the command I needed.

$git clone -b dev 
//-b is a flag that specifies the branch I want

Next is 'update'; Git doesn't have this. After more searching, I found 'fetch' and 'pull'. They both 'update' your local copy, but 'pull' also merges the repo changes with your local changes. Fetch only updates the history of the changes and doesn't merge the changes; 'pull' is what I really needed.

$git pull origin dev 
//this gets the changes from the origin of the dev branch and merges with my local copy

Lastly, add and commit. The Git version of these commands have a bit more to it. Git has the concept of a local repo and the git repo. When you're ready with changes or new files, run a 'git status'. This will list the files modified and new files if there is any. In order to get these changes to the git repo, we need to 'add' the changes which prepares them to be committed. Commit only gets the changes written to your local repo. Finally, the last thing we need to do is 'push' the commits to git. The 'push' command sends the commits to the git repo where we want them.

$git add . 
//I'm currently in my root folder, so I'm adding all my changes.

$git commit -m "some message" //commits changes to local repo, -m is a flag for a commit message
$git push origin dev //pushing my commits back to dev in the git repo

Here's a quick run through: SVN: checkout, update, add, commit Git: clone, pull, add, commit, push It's basically one extra step to get changes to git. I'm not an expert with git yet, but this was my experience when I started using it. Hopefully, this helps explain things for other people new to git. If you have any other tips for someone transitioning over, please feel free to leave a comment!