en de

GIT – do I need that?

Posted on Fr 26 Juli 2019 in Computer & Electronics

I am not a professional software developer. But I write code. For fun in Python or C but also for my job – e.g. R-Scripts for data analysis or LaTeX documents.

When I got started with programming as a teenager, I had now idea what version control was. Later, I discovered SCCS and RCS but thought that this was too complex and why would I need that since I was programming on my own, anyway?

Whenever I felt like preserving a version, I would copy everything into an archive directory or roll a zip file/tarball with a version number. I felt that's good enough.

But, of course, little mishaps occured every now and then and I gave CVS a serious try. I didn't really like it. It does not require a server but still want's to keep everything in a CVSROOT folder so my versioning data lives far away from the actual project. I felt that was not very handy for small projects. So it took some time until I turned into a verion control freak.

But why?

So why would I need this? What's wrong with manually saving versions of your work in an archive folder?

Well, it takes quite a bit of discipline to actually do that in your daily work. You have to take care of your version numbering all the time. It is also not easy to keep track of what changes were actually made between versions. Finally, duplicating each and every file takes some toll on your disk space. So better only save files that were changed? Don't – unless you want to really loose track of your archive folder. In other words: this approach sucks.

Once you got started with version control you'll see new applications pop up constantly: HTML code of your homepage, my blog, my R/LaTeX scripts or the vimwiki I'm using to document computer related things.

It also feels great to know I can always go back to a previous (working) version of things. E.g. after playing with a wild idea for a feature or some code refactoring.

Enter: git

It's been a few years since my half-assed CVS experiment and I had noticed that there are better alternatives to the old fashioned tools: SVN or Mercurial looked pretty good. However I only got excited when I finally discovered git

Git has many advatages like distributed/decentralized version control, great merge suppport, GitHub etc., speed, flexibility and so on. That sounded promising. I was also impressed that it was used to manage large projects like the LINUX kernel. Also, the decentralized concept sounded very good: I tinker with my own code most of the time but if needed I could send everything to a shared central repository.

I didn't really need most of the fancy features but you never know. And nothing forces you to use features you don't need, yet. So as a solo-programmer you can start slowly into version control with git. Without a server or large infrastructure, without much ado – simply on my laptop in my project folder.

I think, most of the cool pro-features git has to offer can be pretty intimidating for the novice. You need to grasp concepts like merge, pull, clone and push that seem obscure, at first. Don't get me wrong – I really love these things and use them all the time now, but getting over the first hurdle is what counts in winning new git users. Not so much for professional programmers – they learn these things during their education/training/work and for them version control feels natural. But for the little hobby coder who just wants to get some code for his Arduino or her first Python scripts to work, simplicity is key.

I know, many people call git complicated for it does powerful and complex things. But getting started is actually very easy! You can always learn about the fancy stuff, later when that investment of time is justified.

Git for beginners in 2 minutes

Proof: everything you need to know as a beginning git user in one section:

Go to your project folder.

cd ~/programming/rocketcontrollsoftware

Hey git, I'd like to have a repository, here.

git init

Hi git, I'd like to add these files to my version control.

git add launch.c launch.h Makefile spacecraft-configs/

Git, can you store these versions of the files I just added, please? (commit)

git commit -m "Initial Version"

Hey git, what files did I change or add since my last commit?

git status

Hi git, I wrote that really cool new feature. The following files are new or changed.

git add launch.c moonlander.c moonlander.h

Git – please save these changes in my repository.

git commit -m "Add moonlander functionality"

Hey git, show me what I have committed in the past.

git log

Giiiiiit – I screwed up and now nothing works! Pleeeeaaaaase restore the previous state!

git checkout master

Thanks! You saved my life!

That's it. That's all you need to know for a start. Sure – you will need to recover a specific version at some point or look at diffs, create branches, use GitHub or add someone to the team. But for now, that's all you need.

Higher goals

Git is powerful – very powerful. So there are many other concepts you want to wrap your head around, at some point. There is plenty of excellent documentation out there. E.g. The Pro Git book, that I like a lot. If you don't there are many other sources: Books, man pages, online tutorials, videos, developer forums (like stack overflow) etc.

I have turned into a big git fan and put pretty much everything under version control, now.