A beginners guide to git how to!


Let me first tell you what all I am going to tell you.

If you are coming from the world of svn/cvs (like me), I am going to tell you how to do git equivalent of

svn checkout ( git clone)

svn commit = (git add + git commit + git push)

What I am not going to tell you is how to setup your git account, create a new git repo etc, as the existing documentation on git is pretty good for these.

Ok, so lets begin now. I am assuming that your git account is ready, new files/folders are setup and you want to checkout your project in a new workspace.

In SVN, its a simple

svn checkout {location}

however when we try similar thing in git, we get an error!

git checkout git@github.com:anshprat/myFiles.git
fatal: Not a git repository (or any parent up to mount parent )
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

You see, git checkout is not like svn checkout. What git checkout does is checkout a branch or paths to the working tree.

So to do a fresh git "checkout", you basically have to do a git clone.

git clone git@github.com:anshprat/myFiles.git
Cloning into myFiles...
Enter passphrase for key '/home/anshup/.ssh/id_rsa':
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 3 (delta 0)
Receiving objects: 100% (6/6), done.

Voila! Am done.

Now how to do a git equivalent of svn commit ?

In git, this is broken down into 3 parts:

git add
git commit
git push

In svn, svn add is only for adding a new file to under revision control.
In git, git add, is useful for adding any changes to the index that would be finally merged or committed to the git repo online.

git commit : by this you are confirming that the changed files that you ve added by git add are ready to be committed.

git push: This is the command that finally pushes your changes back to the git repository!

So now you know how to do a "svn checkout and svn commit" using git :P

Look out for more as I delve more into git :)

Written on August 28, 2011