Starting with Git

I had postpone using some kind of VCS for a long time. In the past (way back) I looked at SVN, but did not quite like the fact that it uses a server, maybe because back then I did not understand much how exactly it worked. For some reason, I thought I wold have to move all my projects somewhere else. It is a stupid way of thinking about it, but I was young and a bit more naive than now. Not long ago I looked at git. I installed it, and even created a repository for my core project, but then I felt uneasy using it without really understanding what I was doing, so I deleted the .git folder from core, and forgot about the whole thing.

A couple of weeks ago, I received a quote request, and one of the project requirements was that it be source controlled using git. I honestly informed the client that I had no experience with git, and that I may need help getting started. The client agreed, and the project was on. This week we finally got the good to go for the project, and I immediately had problems.

First, it seems their server was not configured properly, but then when it all worked, I did not know what to do. I was supposed to clone the project that they had initialized, which I did, but then got nothing but an empty directory. Then, after doing git pull all I got was an index.php file that said replace me. I was lost.

Fortunately, one of the guys in the team was very helpful explaining what was going on, but more importantly, he provided me with some good resources ( that I could read. That helped me a lot, and I’ve been reading a few articles and resources about git. If you are new to git, I recommend the next few reads:

And here is a cheat sheet.

Once you’ve understood the basics of git, you can continue with this reads about git submodules, and why you might not want to use them, as well as some options.

Finally, this explains how to get rid of a submodule, in case you want to try them and later decide that you don’t really like them.

I asked a question on stackoverflow, where someone said I should not start with git as my first VCS. I think this answer is much like when people tell you “don’t use VIM. It is very complicated”. The truth is that, while it is true that VIM is more complicated that a simple text editor, and Git is more confusing than most VCS, there are reason why you should try them. I won’t get into the case of VIM, because that is out of the scope of this post, but in the case of Git, I’ve found a few things I like:

* Everything is local. There is no need to be online, or connected to the server in order to work. You could work offline, and then just push your changes once you can get an internet connection.
* You don’t even need a server. If you are developing on your own, you don’t need a server of any kind, since everything is local.
* Most of everything is kept in .git. When you initialize a repository, most of the changes and settings, and what not, that is related to git, is kept in a directory called .git in the top directory of the repository.
* Once you clone a project, you get the full history, and again, it is all local.
* It is easy to use. Once you understand how it works, it is actually easy to use. I recommend you read the git parable that is linked above. It will really get you to understand git very quickly.

There are of course things that get complicated, like submodules, but just because something is complicated does not mean you should stay away from it.

Yes, I am a beginner. Yes, there are things I don’t know. Yes, I will make mistakes that will make me look stupid. Yes, the person who told me not to use git as my first VCS knows more than me about it an probably had a legitimate reason why he said that. However, there were people saying you should not use VIM, but I did anyway, and to this day I haven’t looked back.

There are times when someone, maybe even me, will try to discourage you from using something or other, but you should always give it a try. Just because I find something hard, does not mean you will too. And even if you do, what is the fun on doing just the easy stuff?