I'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've probably got to use.
I'm not a cool kid and for the last few years (since WordPress started the plugin repository using SVN I think — more or less 8 years ago), I'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?
I'm regularly pestered to move YOURLS from Google Code to Github, to which I responded more or less that I was happy with SVN and I didn't want to spend time learning a new complicated tool. Because, Git is complicated, right?
But I wanted to be a cool kid anyway, so I gave Git a few looks and tries.
First pass: what others say
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 "Git vs SVN" article will list a few amaaaazing advantages, which are always:
Git is distributed. I'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?
Git is fast. Wow. Maybe, but, errr… it's not like I really need to shave 5 seconds off the 15 seconds that my commits take, right?
Git is more efficient, disk wise. I knew that, for instance, Git tags are just pointer to a particular commit, while SVN tags are a joke because it's a whole folder where code is duplicated. And yes, that made sense to me, but I still didn't care because, honestly, who needs tags? I don't. Plus, I can haz gigabytes of empty disk space, so a source control tool that'll save me a few megs isn't really a life saver, right?
These were the pro-Git arguments I've seen everywhere, and I wasn't excited. Sure, seems cool, but definitely not something cool enough to be worth the hassle for me.
Second pass: theory
I searched the web for all the Git manuals, starters, tutorials and handbooks I could find and ended up with reading the Official Git Documentation which is, I must admit, pretty well done.
In every tutorials and guides, the first basic steps are easy and won't get a newbie SVN user lost: you edit a file, you commit it. Wait, then, you push it. Soo… in SVN I edit and commit, but in Git I have to edit, commit then push? Okaaaay…
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 "branching" or incredible log viewing abilities or god knows what.
Seriously, I thought, why on Earth is every cool kid using that tool and advocating it like it's what Jesus and Chuck Norris would use?
Third pass: practicing a bit
One day, I was playing Alchemy on my phone: it'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: "heh, this is fun, I'm sure I could do this in Javascript, it's all about jQuery draggables".
One other day, I came across an article on Github's blog about a Game competition: 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 :)
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's participate.
So I created my first repo in my empty Github account, 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.
Rapidly, three things happened : a "hey cool!", a little relief, and a fucking ZOMYGOD.
The "Hey cool!": where complicated makes sense.
You've already created a SVN repository and found it easy, right? Just set up an online repo, checkout its content to your disk. Can't be easier, right?
Well, yes, it can: inside any directory, click "Create Git Repository here" in TortoiseGit, or "git init" if you're the 2D console type of coder, and that's it, you already have a full-fledged repository where you can commit, revert and track changes.
Suddenly, the three-steps workflow (remember? edit, commit, push) made sense: everything is local! you don't even need an internet connection to work with your repo! No wonder they say it's faster. You can commit and revert locally, then eventually push on the remote repository and share with the world when it's cool enough. Or you can even create a quick repository for a quick local project without even needing an internet repo.
And that, I thought, can be an interesting development pattern.
The Relief: OK, it's actually easy.
Once I understood that 3 step workflow, I didn'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.
The Fucking ZOMG: Git's killer ninja nuclear godzillesque feature: Branching.
OK, onto finally the real reason I'm writing this whole post :)
On Github, once you have a repository (http://github.com/joe), you can also easily publish to a live website (http://joe.github.com), and, for this, you have to create a new branch named 'gh-pages'. 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.
I knew branches from SVN: they are folders where a particular branch of your code lives, and you can modify it without modifying the "master" branch (aka trunk in SVN), to eventually merge branches later. This is probably cool and everything, but it implies juggling with directories and that'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.
So, branches with Git. And now, my fellow SVN-accustomed Git-ignorant coder friend, open your eyes and read carefully what happened.
First, I created the branch 'gh-pages'. "Hmm, I must have done something wrong", I thought, I was expecting something like a new folder named 'gh-pages' where to put new stuff.
Oh, OK, I have to "checkout gh-pages", ie switch to that branch. God knows where that'll take us, but let's do it. I did, and, again, saw nothing particular happen. "Well, I thought, I'm following the step by step tutorial, so let's just pretend this is normal". I added a few stuff in my working directory, and committed.
So far, so good, except I still didn't understand where I was exactly, since I was still working in the same directory. Where'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 "master" branch. And what happened? My newly committed files disappeared.
Since I was sober at that time and pretty sure I had created and committed files, I boldly didn't panick, didn'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!!
Today I began playing with Git branches, and, dude… http://t.co/gHhey1IX
— Ozh Richard (@ozh) November 6, 2012
Look at the following two images — for the sake of screenshotting I use the command line client, but TortoiseGit has the same ability — you can switch between branches without having to work in different directories.
That. That is pure awesomeness. Why on Earth isn't this mentionned in bold typeface on every Git vs SVN article? "Git is magic and changes branches without bothering you with different folders". Forget about all the distributed shit and other history logging stuff, THIS is the crack.
"And why is that so cool", may ask the one or two readers still with us at that point?
Imagine working on your regular project, WordPress plugin, whatever. You're coding and seeing live results in http://127.0.0.1/myproject and suddenly you want to test something crazy in uncharted territories. Chances are, you make a copy of plugin.php and library.js, and begin modifying them. So, basically, you'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're happy with the result, merge back (another click). No need to have multiple directories to keep duplicate files.
That is fucking awesome. 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.
So, whatcha think, Ozh?
Man, I'm sold. Did I say this is awesome already? I'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, life changing. I even tried to explain how cool that is to my wife, but that battle remains yet to be won ;)
There are a lot of complicated things in Git because, again, it's a complete hardware store and most of the time, you'll need a simple hammer to do a simple job. And that's fine: just use the hammer, and the one day you need complicated tools to perform a complicated task, you know you'll have something in store and someone or a tutorial to explain how it works.
Retrospectively, I see why I have been a bit hard to convince.
Github is sexy and powerfull, but it's not a Git client
Github is definitely one of the reasons why Git is so succesfull: the interface is sexy and very elegantly functional. It's so beautiful you just have to be a part of that.
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 "pull requests", 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.
Same comments go to their desktop client: sexy apps for sure, but I'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's Git client is appealing, but is half baked. No offense, Github.
Practice first, read later
Sure, that sounds like the dumbest advice ever: everybody knows it's easier to learn something while practicing. But it requires something you may not have at hand by the time you'll want to investigate Git a little: a real life project, no matter how modest, to test drive things. I didn'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't work. Or at least my brain isn't wired that way.
Find the right teacher
As I've said, the official Git documentation is really neat. But it's not a tutorial, it's a reference: it explains it all, including the hardcore complicated stuff, and will quickly get you lost if you're not in desperate need of something hardcore.
The best guide I've found to suit my needs was Git Magic. Pleasantly written, funny even, and advocates just what I wrote above: start little, and if you don't need more than the very basic commands, that's very fine.
I'm not very found of cheat sheets, which I often find pretty and unusable, but I've appreciated that one. It covers a few key concepts and doesn't try to be an all-in-one A4 sheet.
So, I've tried Git, and it's…
(admit it, you've scrolled all the way down to here without reading the article, haven't you? Naughty!)
It's by far one of the most amazing tools I've ever put my hands on. I was happy when I discovered SVN because it was handy, but I'm all wet for having discovered Git because it's magic. I just don't get why heavily collaborative projects such as WordPress don't gitify their platform.
If you'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.
Excuse me, now I need to find myself a Git tshirt, because when I like something, I want a tshirt of it :)
Shorter URL
Want to share or tweet this post? Please use this short URL: http://ozh.in/vj
Haha, a great article. I'll be sending this to the few lingering Git haters I know from now on.
When you want to blow your mind for a 2nd round, add a
-p
to a command. E.g.git commit -p
This is patch mode and a basic explanation can be found here. It can be used with
checkout
,add
,stash
, all the most important Git commands.And if you want a third round of mind being blown, learn how to time travel in Git (if you haven't already). Git Magic's section on rewriting history is excellent.
In a line:
git rebase -i HEAD~n
Where
n
is the number of commits you want to change.Ha! I completely get the excitement :) My use cases are simpler, but magic is magic, eh!? Best guide to my mind is: http://think-like-a-git.net/ best conceptual overview, conversationally written – gives me confidence to play, knowing that everything is a commit, nothing is lost.
I have never been able to get Tortoise Git to work, at all. What's the magic secret?
Otto » err, dunno… I just installed it :) Works nice side by side with TortoiseSVN (too bad you can't have each one using a different icon set)
@Otto, I have two dual-booting notebooks (read: bought with Windows copy already installed and set a Linux on them) and both work fairly well with TortoiseGit (as well as TortoiseSVN and HG versions). Win 7, if that matters, so regarding your issues with the install, there should be something pretty specific in your setup.
@Ozh
I use your YOURLS ;-)
If you ever decide to move it to Git(hub) try https://github.com/nirvdrum/svn2git . Its better way to move stuff from SVN to Git (IMHO)
Rahul Bansal » If I move YOURLS to Github (which may totally happen, but probably when I'm more comfortable with Git) I'll want a tool to import the whole project, ie code, wiki and issues (I think I found one the other day)
One Git tutorial that may be worth checking out:
http://gitimmersion.com/
Full disclosure: it's from the company I work for. We're always happy to hear from new Git users about what could improve the site. Thanks!
Well, I reinstalled TortoiseGit, and after about half an hour of fiddling around with SSH keys, I got it to connect to GitHub. So, it does work now, I'll give it that.
Otto » I saved myself some trouble and instead of using SSH keys I've just saved my Github login/pwd in a _netrc file http://www.programmoria.com/2012/02/saving-tortoisegit-password.html
Making keys wasn't much of a problem, configuring tortoise to use them was extremely non obvious.
@ozh
Are you talking about a tool which allows moving codes, issues, wiki and other stuff from Google Codes project to Github project?
If this is the case, please share more about it in future posts.
Rahul Bansal » For instance, http://trentm.com/2012/03/google-code-to-github.html covers that. Not tried yet, but I'll probably do
@Ozh
Thanks for link. :-)
I never used Google Codes for own projects but glad to know possibility of moving wikis & issues.
hah, interesting take on Git, had me all cracked up! ;)
Btw, curious to know why you found the branch switching in Git new? In SVN you can switch branches/tags as well, TortoiseSVN has the switch feature. So you can only checkout a particular branch/tag of a repo when working in SVN & then switch as per your needs, keeping the single folder instead of checking out the whole repo with branches & tags sub-folders. :)
On that note, Github required the pub/pvt keys, personally one reason I like Bitbucket is that the usage of keys is not compulsory, you can just use the un/pwd pair like you'd do in SVN. :)
amit » that's what I'm talking about: in SVN you need to switch *folders* when going back and forth between multiple branches
I heard mercury was really good, too
@Amit,
Github allows username/password based authentication. Just use HTTP-based URL for a github repo.
In HTTP-authentication case, we need to use Github user/password only.
Ref: https://help.github.com/articles/why-is-git-always-asking-for-my-password
@Amit
Correct link is: https://help.github.com/articles/which-remote-url-should-i-use
@ozh:
you meant that svn creates whole copies of the code to which you switch when switching branches/tags instead of just moving to a particular commit in git as it keeps everything on 1 tree rather than actual branching off?
@Rahul Bansal
Hmm, I use HTTP URLs only on Github but have a pub/pvt key pair setup, seems that isn't required but the article I saw on getting started with Git & Github had that so I just followed it as it is. :)
I came to your article with the exact same question in mind – so why is git so popular? And boy, is your's one of the most enjoyable article I have read in a while. You pretty much took the words out of my mouth as I was reading the article. I've installed a bunch of tools to integrate Git to the Shell, Visual Studio etc and now I see that there's TortoiseGit. So which would you recommend for a Windows Developer who is used to TortoiseSVN and Shell Integration – Git software by Git themselves, Git Extensions or TortoiseGit? Im not so fond of using the GitHub client which is specific to GitHub only.
Sreenath » Thanks for your kind words. Check the next article on that subject, it's about the setup I recommend: http://ozh.in/vl
Enjoyed the article. I am not blown away by git branching, since it just shows that SVN branching is broken. Heres the trollfeed: I still like CVS better than subversion.
I have to admit Git has me in tears tonight. I'm a self taught designer/developer that can code beautiful circles around most people I know. I can skin anything and if I have a set of guidelines I can figure anything out. I'm up to building intricate Drupal sites. But I'm the only developer. We have three servers backed up nightly… And the new contractor shames me about my inability to figure out git. I Haven't command lined since 1991 and can't remember my kids phone number. I can't figure out how to get my beautiful site on the server and I feel like an idiot. The contractor (on a PC) sends me lines of irrelevant stuff that doesn't work on my Mac. Deadline is soon and I've spent days trying to figure out something that was simple before. I'm so lost. Ok, gotta stop crying. I will figure it out.
But learning there was no fail safe to keep my intern overwriting one of my files makes me super happy. my contractor's advice to "communicate over IM" to prevent overlap did not fill me with warm fuzzier.
You summed up how I felt about Git. Biggest git turnoff for me is TortoiseGit. Hideous hideous overcomplex, Linux-geek-designed-UI. TortoiseSVN on the other hand, much more accessible