Git for Gamers Pt. 1 (Git Is Awesome)May 20, 2016
Git is a fantastic tool used for source code version control. It’s quick, light, open-source, and has changed how I code on a daily basis. Git also made me realize how bad my workflow was. Making Git a part of your toolkit can be daunting at first. I’ve drawn some comparisons to how Git relates to something we’re all familiar with, vidya games.
There are many Git workflows out there. I use Git flow. It’s great. Check it out. Most version control workflows are not just limited to Git, but apply to many version control systems. The examples here will use Git because branching in Git is cheap, and it’s awesome.
Let’s get started.
Finally, after camping out at your local GameStop for days, the newest edition of [Insert Medieval RPG Game Name Here] is released. You race home, rip open the packaging, and fire up your console. After downloading ridiculous amounts of updates, you start the game.
git init # Initialize git repo
It’s everything you had hoped for, and more.
Time to customize your character.
# Identity for Git, used in every commit
git config --global user.name “Aererth The Sullen”
git config --global user.email email@example.com
Aererth is an anarchistic mohawked viking-ninja with a mysterious past.
You complete the opening tutorial, and NEVER want to do it again. This is where you save your progress, or in Git lingo, commit.
touch tutorials_are_not_fun_but_necessary.txt # Complete tutorial
git add tutorials_are_not_fun_but_necessary.txt # Stage file for commit
git commit -m “Tutorial complete.”
You start on your journey towards no showers, binge eating pizza, and drinking endless amounts of energy drinks.
First Quest (Branch)
You see a dragon terrorizing some townsfolk in the distance.
You are given 2 choices.
Slay The Dragon
Let Them Burn
Any right mind would play the hero in these types of situations.
git checkout -b SlayTheDragon # Create topic/local branch
Good work. You’re a hero. The townsfolk are super grateful and give you 10 gold. Better save your progress.
touch free_townsfolk.txt # Save townsfolk
git add free_townsfolk.txt # Stage file for commit
git commit -m “Saved the townsfolk.”
Cue the cutscene.
You continue on your adventure, but stop to think on what could have been… 10 gold won’t even cover the durability loss to that sword you looted earlier from that dead chicken.
Git to the rescue.
git revert HEAD # Revert to previous commit
It’s like it never happened. You load your last saved game where, once again, you see the dragon circling the townsfolk. This time, you pop a squat on the boulder up on the hillside to witness the destruction.
git checkout -b LetThemBurn # Create topic/local branch
Congrats. You’re evil. Let’s save our progress.
touch add high_five_dragon_sack_pillage_plunder_50_gold.txt # Do evil things
git add high_five_dragon_sack_pillage_plunder_50_gold.txt # Stage file for committing
git commit -m “Townsfolk dead.” # Perform commit
Worth it. More cutscene.
You continue down a dirt road…