Seriously. Stop reading this post, commit your changes, and push your local branch to whatever remote you want. Just. Fucking. Do. it. How much time does it took? It was nothing, right? Thanks, now I will explain you why.
Repos can get corrupted
Git is a powerful tool, and very stable. But the truth is that can become become corrupt in some weird ways, not all related to Git. Running `git fsck` is one of those thing that you don’t want to do, and that in my experience is useless most of the time.
So you have been hacking for a whole day in your a local branch, of course you don’t like the shape of your code, or it is incomplete or you just forgot about it. Then, by the end of the day, when you run `git status`, instead of lots of uncommited changes and such you see a lot of weird error messages. Oh boy, yes, your local repository has gone nuts, and if you are lucky you will be able to dig into the dozen of changed files to rescue you precious code.
Also, Shit Happens
Lets suppose Git behaves properly, but again shit happens, you hard disk can fail (really that still happens), your motherboard can break or an idiot can spill his Frappucchino over your laptop. And your code keeps laying there, in a local branch, never commited, never pushed to any other repository, below a sticky mess of frozen coffee that starts melting under your watery eyes.
How much have you saved by not committing?
NOTHING you moron, when you started learning git the mantra was “branches are cheap, branches are cheap, branches are cheap, …”, wasn’t it? so now you start a branch for more or less anything from new features to hot fixes in production code.
“The header needs to be shown in a more intense pink?” Branch. “The API has to be refactored to better suit current needs?” Branch. “Your girlfriend called telling you about her best friend who is going to get married.” FUCKING BRANCH DUDE!
So you became branch-addicted, but why for God sake you think that Torvalds himself will invoice you per commit? Why? Why? Why?
Commits are as cheap and fast as branches are in Git, there is no need to reserve commits as they were bottles of a rare old wine. You are saving nothing by not frequently committing your work, except a few CPU cycles of your brain required to be aware of your code state.
Tantric Pushes?!!!! WTF?!!!
Lets suppose not only you branched, but that also you commited as I told you. And then here is your long lived branch day after day, alone, sad and isolated in your box. Until some moment, days or weeks later when you decide that yes, your code can see the light…
WHAT THE FUCK ARE YOU TRYING TO DO? Holding back your orgasm for a cosmic experience? C’mon boy, normal people spend fiften minutes on duty, those two hours intercourses only happen in porn movies.
Git is extremely efficient transmitting objects, also Git is distributed by design. Pushing whatever you have in your branch to another repository will take seconds most of the time, stick your finger in your nose meanwhile if you find this time too long.
But I can’t commit, this code is not ready…
BULLSHIT! Code is never ready, why are you afraid of committing incomplete code? And pushing it into the public light? Dude you are a great programmer, but unless you are a true genius you can’t just connect a pipe from your brain to your text editor or IDE. And your code will be evolving minute after minute, hour after hour, day after day until it rocks.
Whether you belong to the Incremental or Iterative School of Thinking, you will always be reaching little milestones in the evolution of your code that you can label with a short, meaningful commit message. Nothing fancy required, tests doesn’t have to be green, indentation can be fixed later also.
But I will feel dirty when I run `git log`
it is great you finally you started thinking, OK if you follow my advice and commit frequently you will end with a LOT of commits which won’t be useful to describe the evolution of your code to no one. What can you do?
Simple, squash your commits when merging your branch. Squashing will take all those tiny commits and rewrite them to the last state of your branch. In the 365 Git tumblelog you will find a great explanation about your options for squashing.
As you can see Git allows you to branch, commit and frequently push your code in a Fast and Furious way. You have no excuses now.
But is this all about having a backup?
What’s wrong with backups? How frequently is your development box backed up? Is your sandboxes/ folder included in your backups? Nightly? Twice a day?
I am sure you are brilliant enough to code again all the work of the day or the week again, ever with a better twist. But when was last time you went to the beach? Have you seen yourself in the mirror lately Casper?
No, it is not only about cheap backups
The point is using Git to empower your programming practices, being able to explore solutions to your problems in a more flexible way and going back on your tracks without problem, radiate information about what you are doing (post commit hooks anybody?) to your stakeholders.
Maybe I am wrong, for sure I don’t have all the answers, but I think this can be the starting point of something good. What do you think?