Git it up
- Why use Git on “everything”?
- How can Git help me with that?
- Nice. So what?
- Convinced. What should I git up?
I assume you know what Git is. If you don’t, you can find tons of info with a simple search. I also assume you know what “version control” means, and even that you are familiar with Git basics. If you are not, some things here may sound strange to you, but (almost) everything has a solution.
You probably have used Git when publishing something on GitHub, maybe even to keep a big project organized. That is fine. But it could be better.
Here’s the deal. I want to convince you to use Git for everything. Not only for your work, but for everything. Everything. So, I will discuss why you should use it for all your stuff, and some suggestions to do it. Why would you want to do such a thing? Keep reading.
Why use Git on “everything”?
We trust our computers. We trust our hard disks, all of our hardware. We trust our operating systems, the software we run. Sometimes, we even trust The Cloud. We have extremely valuable data, and we think we have the ultimate word over what is happening to that data, because we think we have total control over some things we trust.
The truth is that hardware breaks, software fails, The Cloud is not as safe and private as we like to think, and what we do is not guaranteed to be not-stupid. Our data is not safe. And, if it is valuable enough, we want to protect it, even from ourselves.
Some of the most valuable data we have are the things we do. Not only being in the form of hard work and source code, but also as written articles, a compilation of notes, a CV. Not only that, but also your ToDo list, a list of the favourites app you have in your phone just in case it breaks, your preferred configurations for the software you use. Usually, not very big stuff, but extremely important anyway. After all, there’s a tiny bit of the author in every text file.
Protect from what?
The hard disk may fail, the USB drive may be lost, and, of course, you can mess with your own data; by making undesired changes or even deleting it. Or am I the only one who “rm -rf” too much?
And will Git protect my stuff?
Yes. Git is an extremely flexible and powerful tool, it has several features that can guarantee the integrity of your data; and if you use it correctly, it will protect your important stuff. Let me explain myself.
How can Git help me with that?
Excellent question, dear me. As said, Git has several security features, allowing you to effectively armor your beloved files. For example:
Git is cryptographically safe. Every commit you do has a hash. They are chained, making each hash dependent on the previous one. No one can modify your commits, not even yourself, without alter the hash chain. This ensures the total integrity of every file you are versioning.
Git remembers everything. You want to recover the file you just deleted? Done. You want to see the changes you did a month ago? Done. You want to revert the modifications your SO did to your Sacred List of Family Recipes? Done. It’s fine, Git remembers.
Git is distributed. What’s the point in having your stuff well versioned, if your computer may explode in any moment? Git to the rescue. You can have several remotes, making your data redundant. If your laptop get stolen, or if your hard drive dies, you will have a copy on your remotes. Even if one of your remotes is down, you can have many, in different places. Nothing will make your data survive the Ragnarok, but it sure will be several orders of magnitude safer than having it just stored on your PC.
Git has branches. If you want to try some alternative way to do something in your software, and you don’t even know if that thing could work, you can consider using an experimental branch. Or if you want to add a few lines to your CV, only relevant to some type of companies, without changing your main one. Or if you want to add a few verses to your last poem, but you’re not so sure if you will keep them. Or if you’re writing an article in your website you don’t want to publish it until it’s finished. For any thing you want to do that implies following a different logical path than the main, or any part you don’t want to add right now, use branches.
Your versioned files can be synchronized, if you want. This is a side-effect of the fact that Git allows you to have remote branches. If you use more than one computer, you can propagate the changes you do in one of them, to the rest. This could be extremely useful to sync configurations of your software, so you can have it everywhere. Just in case you don’t feel comfortable programming using a hostile environment instead of your nice and warm Vim (or Emacs).
Git is collaborative. You can share a Git repo with other people. Working on software together is not the only thing you can do involving Git and more people. Maintain a list of suggested ideas to do on holidays with your SO. Organize a surprise party with your friends. Share your thoughts about a book you are reading within a book club, using branches to avoid spoilers. Git is social and collaborative, and you can make profit out of it.
These are some of the features that make Git awesome, and the most important ones that make Git awesomely good to trust it your work.
Nice. So what?
So, you should Git everything up.
A while ago, I used Git as a tool to share some code with some people in some project, and nothing else. After some talking with a friend about how he used (and still uses) Git, I decided to give it a try.
The first thing I did was to organize my dotfiles in a folder, and start to version-control that folder. I became more organized, I could move my configuration to other computers without effort, everything was stored in remote branches, and I could see every change done in the configuration. And it was awesome.
Since that day, for every programming project I start, the very first thing I
do is a
git init. Even the smallest one, even just a silly experiment. I
always git it up.
But that’s not all. After I started using Git for every programming project, and after it saved my stuff several times (mainly from myself), I decided to give the next step. I started to git everything up. My CV, written in LaTeX, is under Git control; different changes are in branches. My ToDo list is versioned, and synchronized. My website is gitted up, and new articles and pages are in different branches.
Convinced. What should I git up?
Just use your imagination. Protect your stuff, even your less important stuff. You need some ideas? Here are some things that I do, that someone I know does, or that I think it would be a good idea if applied:
If you version your dotfiles, you will never lose your configuration, and it will be available for other computers; making the set-up of a new computer really easy. Pro tip: While you can use an install script to configure your stuff, if you use a software with text-based configuration to manage your dotfiles, it will be even easier to install and update them.
As said before, git your CV up. This works if you’re doing it with LaTeX, with HTML, or with other plain-text-based compositor. Pro tip: If you are looking for a job, you know your CV should may need some details depending on where are you sending it. Use branches to hold these changes and to generate the document you’re sending, and delete them when you’re done.
You can version a list of the movies you want to see or the books you want to read. Pro tip: You can use the log to see the exact date you saw a movie or read a book.
Have a ToDo list versioned. It will help you to be more productive, to not forget about important things and to remember when you did something. Pro tip: Use remotes to synchronize the ToDo list between computers, so it’s always updated.
If you have a static blog or website (e.g. based on Jekyll), you can version it to keep track of the changes you have made. Pro tip: Use branches to write new articles you don’t want to publish until finished. Merge the new contents to Master when you want them to appear.
Make a recipe book. When you improve them, your changes will appear in the log, and you can use these changes to get ideas for other recipes. Pro tip: Share the recipe book with your family (if you can teach your mom how to use Git) or your friends. Everyone can add their recipes, and see how the others have improved theirs. Pro Tip 2: Use branches for your cooking experiments.
Make a simple wiki with the code snippets that may be useful one day, with that command you never remember, with that cool piece of code you saw on the Internet. You will have all that knowledge always available. Pro tip: Publish your wiki to somewhere online (even like GitHub pages, which is free), so you have it always available.
Keep track of your improvements in some area. If you are trying to gain/lose weight, if you just started C25K, if you try to break your record in Super Hexagon… Just anything you can track. The log will show you how fast you improve, and when you got your better results. Pro tip: Are you proud of your results? Publish them in a blog or small website.
The sky is the limit. Git it up!