{"id":1808,"date":"2012-11-13T01:22:30","date_gmt":"2012-11-12T23:22:30","guid":{"rendered":"http:\/\/planetozh.com\/blog\/?p=1808"},"modified":"2012-11-13T01:22:30","modified_gmt":"2012-11-12T23:22:30","slug":"so-ive-tried-git-and-its","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2012\/11\/so-ive-tried-git-and-its\/","title":{"rendered":"So, I&#8217;ve Tried Git. And it&#8217;s&#8230;"},"content":{"rendered":"<p>I&#39;m a SVN user.<\/p>\n<p>Nowadays, all the cool kids have a <a href=\"https:\/\/github.com\/\">Github<\/a> account where they host stuff and use <strong>Git<\/strong> as their primary Source Control tool, and prefer it over the usual <strong>SVN<\/strong> you&#39;ve probably got to use.<\/p>\n<p>I&#39;m not a cool kid and for the last few years (since WordPress started the plugin repository using SVN I think &#8212; more or less <a href=\"http:\/\/plugins.trac.wordpress.org\/changeset\/1358\">8 years ago<\/a>), I&#39;ve been happily using SVN. You know SVN, right? Easy to use and to understand, right? Does the job simply, right? So, why switch, right?<\/p>\n<p>I&#39;m regularly pestered to <a href=\"http:\/\/blog.yourls.org\/2012\/08\/should-yourls-be-on-github-instead\/\">move YOURLS from Google Code to Github<\/a>, to which I responded more or less that I was happy with SVN and I didn&#39;t want to spend time learning a new complicated tool. Because, Git is complicated, right?<\/p>\n<p>But I <em>wanted<\/em> to be a cool kid anyway, so I gave Git a few looks and tries.<\/p>\n<p><!--more--><\/p>\n<h2>First pass: what others say<\/h2>\n<p>A couple months ago, I decided to investigate that Git stuff. From a few blog posts I skimmed through here and there, I knew that Git was supposed to have a few advantages over SVN. Any &quot;Git vs SVN&quot; article will list a few amaaaazing advantages, which are always:<\/p>\n<p><strong>Git is distributed<\/strong>. I&#39;ll be damn if that made sense to me: what I need is a computer where I code and a repo where I commit, right?<\/p>\n<p><strong>Git is fast<\/strong>. Wow. Maybe, but, errr&#8230; it&#39;s not like I really need to shave 5 seconds off the 15 seconds that my commits take, right?<\/p>\n<p><strong>Git is more efficient, disk wise<\/strong>. I knew that, for instance, Git tags are just pointer to a particular commit, while <a href=\"http:\/\/scribu.net\/blog\/svn-tagging-is-a-joke.html\">SVN tags are a joke<\/a> because it&#39;s a whole folder where code is duplicated. And yes, that made sense to me, but I still didn&#39;t care because, honestly, who needs tags? I don&#39;t. Plus, I can haz gigabytes of empty disk space, so a source control tool that&#39;ll save me a few megs isn&#39;t really a life saver, right?<\/p>\n<p>These were the pro-Git arguments I&#39;ve seen everywhere, and I wasn&#39;t excited. Sure, seems cool, but definitely not something cool enough to be worth the hassle for me.<\/p>\n<h2>Second pass: theory<\/h2>\n<p>I searched the web for all the Git manuals, starters, tutorials and handbooks I could find and ended up with reading the <a href=\"http:\/\/git-scm.com\/doc\">Official Git Documentation<\/a> which is, I must admit, pretty well done.<\/p>\n<p>In every tutorials and guides, the first basic steps are easy and won&#39;t get a newbie SVN user lost: you edit a file, you commit it. Wait, then, you <em>push<\/em> it. Soo&#8230; in SVN I edit and commit, but in Git I have to edit, commit <em>then push<\/em>? Okaaaay&#8230;<\/p>\n<p>Then, in every tutorials and guides, my interest went decreasing as I was reading more and more about complicated concepts and features light-years from my actual needs, such as &quot;branching&quot; or incredible log viewing abilities or god knows what.<\/p>\n<div id=\"attachment_1815\" style=\"width: 295px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/git-diagram.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1815\" class=\"size-medium wp-image-1815\" title=\"git-diagram\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/git-diagram-285x300.png\" alt=\"\" width=\"285\" height=\"300\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/git-diagram-285x300.png 285w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/git-diagram.png 522w\" sizes=\"auto, (max-width: 285px) 100vw, 285px\" \/><\/a><p id=\"caption-attachment-1815\" class=\"wp-caption-text\">OK, I&#39;m lost. What am I trying to do, again?<\/p><\/div>\n<p>Seriously, I thought, why on Earth is every cool kid using that tool and advocating it like it&#39;s what Jesus and Chuck Norris would use?<\/p>\n<h2>Third pass: practicing a bit<\/h2>\n<p>One day, I was playing <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=me.zed_0xff.android.alchemy&amp;hl=en\">Alchemy<\/a> on my phone: it&#39;s a fun little game where you combine elements by dragging one on top of another, and sometimes it creates a new one (like, drag the Earth icon over the Fire icon and boom, it creates Lava, something like this). I thought: &quot;heh, this is fun, I&#39;m sure I could do this in Javascript, it&#39;s all about jQuery draggables&quot;.<\/p>\n<p>One other day, I came across an article on Github&#39;s blog about a <a href=\"https:\/\/github.com\/blog\/1303-github-game-off\">Game competition<\/a>: create a web based game loosely related to cloning, merging, forking, or anything Git-esque. Nice initiative from them, the world always needs more web based games :)<\/p>\n<p>And finally, one other day, I realized that Alchemy was loosely related to these Git concepts: you clone Earth and you merge it with Fire to create something. Heh, I thought. Why not. Let&#39;s participate.<\/p>\n<p>So I created my first repo in my empty <a href=\"https:\/\/github.com\/ozh\">Github account<\/a>, and I started something different: not trying to learn Git from theory and books, but from real practice, just step by step, humble newbie step by cautious newbie step.<\/p>\n<p>Rapidly, three things happened : a &quot;hey cool!&quot;, a little relief, and a <strong>fucking ZOMYGOD<\/strong>.<\/p>\n<h2>The &quot;Hey cool!&quot;: where complicated makes sense.<\/h2>\n<p>You&#39;ve already created a SVN repository and found it easy, right? Just set up an online repo, checkout its content to your disk. Can&#39;t be easier, right?<\/p>\n<p>Well, yes, it can: inside any directory, click &quot;Create Git Repository here&quot; in TortoiseGit, or &quot;<tt>git init<\/tt>&quot; if you&#39;re the 2D console type of coder, and that&#39;s it, you already have a full-fledged repository where you can commit, revert and track changes.<\/p>\n<p>Suddenly, the three-steps workflow (remember? edit, commit, push) made sense: everything is local! you don&#39;t even need an internet connection to work with your repo! No wonder they say it&#39;s faster. You can commit and revert locally, then eventually push on the remote repository and share with the world when it&#39;s cool enough. Or you can even create a quick repository for a quick local project without even needing an internet repo.<\/p>\n<p>And that, I thought, can be an interesting development pattern.<\/p>\n<h2>The Relief: OK, it&#39;s actually easy.<\/h2>\n<p>Once I understood that 3 step workflow, I didn&#39;t find Git any harder to use than SVN for my very basic needs: code, try, edit, change, revert, edit, fix, save. Sure, it can be a frustrating feeling to use 3 simple commands where there seems to be like 300 complicated ones, but when you just need a hammer and are given a complete hardware store, well, just use the hammer.<\/p>\n<h2>The Fucking ZOMG: Git&#39;s killer ninja nuclear godzillesque feature: Branching.<\/h2>\n<p>OK, onto finally the real reason I&#39;m writing this whole post :)<\/p>\n<p>On Github, once you have a repository (<tt>http:\/\/github.com\/joe<\/tt>), you can also easily publish to a live website (<tt>http:\/\/joe.github.com<\/tt>), and, for this, you have to create a new branch named &#39;<tt>gh-pages<\/tt>&#39;. Since I wanted my web based game to be, well, playable on the web, I thought it might be a nice occasion to play with Git branches.<\/p>\n<p>I knew branches from SVN: they are folders where a particular branch of your code lives, and you can modify it without modifying the &quot;master&quot; branch (aka trunk in SVN), to eventually merge branches later. This is probably cool and everything, but it implies juggling with directories and that&#39;s cumbersome. I for one is annoyed by the trunk\/branch\/tag directory structure enforced by SVN. I want to code in a live directory on my web server, and SVN insists that I copy that into a lame trunk\/branch\/tag folder.<\/p>\n<p>So, branches with Git. And now, my fellow SVN-accustomed Git-ignorant coder friend, open your eyes and read carefully what happened.<\/p>\n<p>First, I created the branch &#39;<tt>gh-pages<\/tt>&#39;. &quot;Hmm, I must have done something wrong&quot;, I thought, I was expecting something like a new folder named &#39;<tt>gh-pages<\/tt>&#39; where to put new stuff.<\/p>\n<div id=\"attachment_1810\" style=\"width: 323px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1810\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture1-master.png\" alt=\"\" title=\"capture1-master\" width=\"313\" height=\"202\" class=\"size-full wp-image-1810\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture1-master.png 313w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture1-master-300x193.png 300w\" sizes=\"auto, (max-width: 313px) 100vw, 313px\" \/><p id=\"caption-attachment-1810\" class=\"wp-caption-text\">Just created a new branch. But where is it?<\/p><\/div>\n<p>Oh, OK, I have to &quot;<tt>checkout gh-pages<\/tt>&quot;, <em>ie<\/em> switch to that branch. God knows where that&#39;ll take us, but let&#39;s do it. I did, and, again, saw nothing particular happen. &quot;Well, I thought, I&#39;m following the step by step tutorial, so let&#39;s just pretend this is normal&quot;. I added a few stuff in my working directory, and committed.<\/p>\n<div id=\"attachment_1811\" style=\"width: 323px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1811\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture1-branch.png\" alt=\"\" title=\"capture1-branch\" width=\"313\" height=\"202\" class=\"size-full wp-image-1811\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture1-branch.png 313w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture1-branch-300x193.png 300w\" sizes=\"auto, (max-width: 313px) 100vw, 313px\" \/><p id=\"caption-attachment-1811\" class=\"wp-caption-text\">Adding a new file in that, well, &quot;branch&quot;<\/p><\/div>\n<p>So far, so good, except I still didn&#39;t understand where I was exactly, since I was still working in the same directory. Where&#39;s main branch? and the new gh-branch? I was slowly getting lost, so I decided to start all over again, and switched back to the &quot;master&quot; branch. And what happened? My newly committed files disappeared.<\/p>\n<div id=\"attachment_1810\" style=\"width: 323px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1810\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture1-master.png\" alt=\"\" title=\"capture1-master\" width=\"313\" height=\"202\" class=\"size-full wp-image-1810\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture1-master.png 313w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture1-master-300x193.png 300w\" sizes=\"auto, (max-width: 313px) 100vw, 313px\" \/><p id=\"caption-attachment-1810\" class=\"wp-caption-text\">Ho noes! My new file! All gone!<\/p><\/div>\n<p>Since I was sober at that time and pretty sure I had created and committed files, I boldly didn&#39;t panick, didn&#39;t move for a few second, hands hovering over the keyboard, and slowly started to realize and understand. Oh. My. Gawd. You can work on multiple branches, it just happens in the same directory. Git just make files appear and disappear as they belong to the current branch or not. Oh. My. FUCKINGGODTHISISAWESOME!!!1!!<\/p>\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\">\n<p lang=\"en\" dir=\"ltr\">Today I began playing with Git branches, and, dude&#8230; <a href=\"http:\/\/t.co\/gHhey1IX\">http:\/\/t.co\/gHhey1IX<\/a><\/p>\n<p>&mdash; Ozh Richard (@ozh) <a href=\"https:\/\/twitter.com\/ozh\/status\/265879562183901184?ref_src=twsrc%5Etfw\">November 6, 2012<\/a><\/p><\/blockquote>\n<p><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<p>Look at the following two images &#8212; for the sake of screenshotting I use the command line client, but TortoiseGit has the same ability &#8212; you can switch between branches without having to work in different directories.<\/p>\n<div id=\"attachment_1812\" style=\"width: 559px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1812\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture2-master.png\" alt=\"\" title=\"capture2-master\" width=\"549\" height=\"242\" class=\"size-full wp-image-1812\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture2-master.png 549w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture2-master-300x132.png 300w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><p id=\"caption-attachment-1812\" class=\"wp-caption-text\">Switching back and forth between branches &#8230;<\/p><\/div>\n<div id=\"attachment_1809\" style=\"width: 559px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1809\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture2-branch.png\" alt=\"\" title=\"capture2-branch\" width=\"549\" height=\"242\" class=\"size-full wp-image-1809\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture2-branch.png 549w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2012\/11\/capture2-branch-300x132.png 300w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><p id=\"caption-attachment-1809\" class=\"wp-caption-text\">&#8230; while staying in the same directory. I could do this all day long.<\/p><\/div>\n<p>That. That is pure awesomeness. Why on Earth isn&#39;t this mentionned in bold typeface on every Git vs SVN article? <strong>&quot;Git is magic and changes branches without bothering you with different folders&quot;<\/strong>. Forget about all the distributed shit and other history logging stuff, THIS is the crack.<\/p>\n<p>&quot;And why is that so cool&quot;, may ask the one or two readers still with us at that point?<\/p>\n<p>Imagine working on your regular project, WordPress plugin, whatever. You&#39;re coding and seeing live results in <tt>http:\/\/127.0.0.1\/myproject<\/tt> and suddenly you want to test something crazy in uncharted territories. Chances are, you make a copy of <tt>plugin.php<\/tt> and <tt>library.js<\/tt>, and begin modifying them. So, basically, you&#39;re working with duplicate files. Meh. In Git, simply create a new branch off your current work (one click or a console one-liner), edit, revert, and if you&#39;re happy with the result, merge back (another click). No need to have multiple directories to keep duplicate files.<\/p>\n<p>That is <strong>fucking awesome<\/strong>. Seriously, people writing guides about how cool and practical Git is, make this big and bold and clear and unmissable from the start. Forget about the rest, emphasize THIS.<\/p>\n<h2>So, whatcha think, Ozh?<\/h2>\n<p>Man, I&#39;m sold. Did I say this is awesome already? I&#39;ve only seen and understood the tip of the iceberg, I may even never need more, but initializing a repo in a blink and instantly switching between branches is, dare I say it, <strong>life changing<\/strong>. I even tried to explain how cool that is to my wife, but that battle remains yet to be won ;)<\/p>\n<p>There are a lot of complicated things in Git because, again, it&#39;s a complete hardware store and most of the time, you&#39;ll need a simple hammer to do a simple job. And that&#39;s fine: just use the hammer, and the one day you need complicated tools to perform a complicated task, you know you&#39;ll have something in store and someone or a tutorial to explain how it works.<\/p>\n<p>Retrospectively, I see why I have been a bit hard to convince.<\/p>\n<h2>Github is sexy and powerfull, but it&#39;s not a Git client<\/h2>\n<p><a href=\"https:\/\/github.com\/\">Github<\/a> is definitely one of the reasons why Git is so succesfull: the interface is sexy and very elegantly functional. It&#39;s so beautiful you just have to be a part of that.<\/p>\n<p>Its paradoxical limitation is that it can give newcomers the false impression everything can be done from within the web interface: share with the world, receive and review patches aka &quot;pull requests&quot;, patch your code. So, when the said newcomer wants to perform something a little more complicated, newcomer gets lost because newcomer cannot find the appropriate menu for the desired action. I was that newcomer.<\/p>\n<p>Same comments go to their desktop client: sexy apps for sure, but I&#39;d recommend skipping them. I started Git with the Github client because I thought it would be easier, but everything got much more intuitive when I installed TortoiseGit which combines simple and powerful. Github&#39;s Git client is appealing, but is half baked. No offense, Github.<\/p>\n<h2>Practice first, read later<\/h2>\n<p>Sure, that sounds like the dumbest advice ever: everybody knows it&#39;s easier to learn something while practicing. But it requires something you may not have at hand by the time you&#39;ll want to investigate Git a little: <strong>a real life project<\/strong>, no matter how modest, to test drive things. I didn&#39;t have a new project to play with when I first tried Git, and following step by step tutorials in a meaningless directory over random files just doesn&#39;t work. Or at least my brain isn&#39;t wired that way.<\/p>\n<h2>Find the right teacher<\/h2>\n<p>As I&#39;ve said, the official <a href=\"http:\/\/git-scm.com\/docs\/\">Git documentation<\/a> is really neat. But it&#39;s not a tutorial, it&#39;s a reference: it explains it all, including the hardcore complicated stuff, and will quickly get you lost if you&#39;re not in desperate need of something hardcore.<\/p>\n<p>The best guide I&#39;ve found to suit my needs was <a href=\"http:\/\/www-cs-students.stanford.edu\/%7Eblynn\/gitmagic\/\">Git Magic<\/a>. Pleasantly written, funny even, and advocates just what I wrote above: start little, and if you don&#39;t need more than the very basic commands, that&#39;s very fine.<\/p>\n<p>I&#39;m not very found of cheat sheets, which I often find pretty and unusable, but I&#39;ve appreciated <a href=\"http:\/\/zrusin.blogspot.fr\/2007\/09\/git-cheat-sheet.html\">that one<\/a>. It covers a few key concepts and doesn&#39;t try to be an all-in-one A4 sheet.<\/p>\n<h2>So, I&#39;ve tried Git, and it&#39;s&#8230;<\/h2>\n<p>(admit it, you&#39;ve scrolled all the way down to here without reading the article, haven&#39;t you? Naughty!)<\/p>\n<p>It&#39;s by far one of the most amazing tools I&#39;ve ever put my hands on. I was happy when I discovered SVN because it was handy, but I&#39;m all wet for having discovered Git because it&#39;s magic. I just don&#39;t get why heavily collaborative projects such as WordPress don&#39;t gitify their platform.<\/p>\n<p>If you&#39;re nice to your sister, a next post will briefly (briefly that time, I promise:) cover a few environment tricks on Windows to make you comfortable with Git. Nothing rocket science, just a few tips.<\/p>\n<p>Excuse me, now I need to find myself a Git tshirt, because when I like something, I want a tshirt of it :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;m a SVN user. Nowadays, all the cool kids have a Github account where they host stuff and use Git as their primary Source Control tool, and prefer it over the usual SVN you&#39;ve probably got to use. I&#39;m not a cool kid and for the last few years (since WordPress started the plugin repository [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[396,397,1,283],"class_list":["post-1808","post","type-post","status-publish","format-standard","hentry","category-published","tag-git","tag-github","tag-my-life","tag-svn"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/1808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/comments?post=1808"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/1808\/revisions"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=1808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=1808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=1808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}