Surely, by now, you’ve heard of GitHub. (Don’t call me surely.) It’s totally the Indiana Jones of repository hosts. Feel free to stalk Pj and I to see what we’re up to. Blogging be damned!
If you haven’t heard of GitHub, there are tons of posts explaining the hows and whys of its awesomeness. This is not one of the posts. Instead, I want to quickly share some oft overlooked but tasty GitHub tidbits.
The GitHub Gem
GitHub supports gems, which is cool, and also means we can install the official GitHub gem with ease:
$ gem install defunkt-github --source=http://gems.github.com/
Great. At this point, possibilities become reality. The gem has a few cool features, all of which are displayed via $ github -h, but the best feature by far is pull.
Here’s how it works: I have my fork of technoweenie’s exception_logger. I’ve cloned it and am sitting in the working directory. Suddenly I discover ryanb (of RailsCasts fame) has sent me a pull request. Open source’s finest moment.
So, I type $ github pull ryanb. A remote is added, a new branch is created, and Ryan’s changes are pulled into that branch. (It’s probably named ryanb/master.) I then review the changes and, if they rock, either rebase or merge them back into master. Like this:
$ git checkout master $ git merge ryanb/master $ git push
Already reviewed the changes on the web and know they’re legit? Just $ github pull --merge ryanb. This’ll grab the changes and merge them into master for you. Oh, right, you can also specify a branch. The assumption is master, but you know what they say about assumptions: you’re a jerk.
Thus: $ github pull—merge ryanb weird_branch
And just like that, GitHub pull requests are no longer a pain in the ass.
But really, this is just start. Please please please fork the gem and add awesome features. github clone, anyone?
Keyboard Shortcuts
Let’s say you want to peep some Rails changes. In classic vi style, j and k navigate between changes. c, t, and p lead you to the selected change’s commit, tree, or parent. h and l navigate between pages.
In fact, h and l will always go back and forward on any paginated page. We’ve written an evil twin which adds those hotkeys to any will_paginate call.
Also cool: s. If you’re logged in, hitting s will display and focus the search bar. I use this one the most.
Ranged Code Highlighting
Clicking on any line number then shift clicking a higher value line number selects a range. Super useful for code discussion. Discussion such as, “Dude, nonzero? is so awesome. Check it out!” (People definitely talk like that.)
Sweet.
Keep Your Dotfiles in Git
Okay, this isn’t strictly related to GitHub, but it’s good. You should be keeping your dotfiles in Git. Here are the steps to do so:
1. Create a ‘dotfiles’ directory.
2. Move your dotfiles to this new directory, sans leading dot. For example, to keep your ˜/.vimrc under version control, do this:
$ mv ˜/.vimrc ˜/Projects/dotfiles/vimrc. Rinse and repeat as necessary.
3. Add the following file to your dotfiles project, then run it: http://pastie.org/195036
4. Finally: $ git init && git add . Then: $ git commit -m ‘new dotfiles project’
You’re all set. Now your dotfiles that live in ˜ are symlinked to their counterparts in ˜/Projects/dotfiles. As a bonus, any time you git commit it will automatically git push. One of the entire points of keeping your files under version control is to back them up regularly.
I push to a private ‘dotfiles’ repo on GitHub. Others have created public repos. Your call.
For posterity’s sake, here’s my version controlled dotfiles:
bashrc gitconfig irbrc railsrc sake screenrc ssh vim vimrc
The best part?
The best part about GitHub, f’sure, is all the outrageously cool open source projects hosted on it. _why’s stuff, the jQuery plugins and mirrors, all the LISP projects, newer languages like Io, and of course the assorted GitHub-related projects.
Got something cool hosted there? Let us know.
Til next time, keep on hubbin’.
Update: GitHub Open Sores
I just created the GitHub account and did two things: created and pushed up some extractions from GitHub itself (like the jQuery hotkeys plugin) and also forked all the projects that are used on GitHub which we’re using on GitHub. Dude, meta. Anyway, have fun with that.
I didn’t know about that gem support! Very cool.
Correcting a peeve (sorry):
“Feel free to stalk Pj and I to see what we’re up to.”
That is trying too hard to be grammatical. :) If you would have used “I” if it was just you, then say “PJ and I”; if you would have used “me”, say “PJ and me”.
So it’s “Feel free to stalk PJ and me” but “PJ and I sat in a tree”.
Woohoo GitHub!
I liked the part about dotfiles. I changed it a little bit though. Made the install-script like this; http://pastie.org/195093 (almost identical), and added the hook-things on my own. Additionally, I added the install-script as a hook, so it creates new symlinks automatically when I commit.
Is it possible maybe that you can share the vimrc file with us? I just switched to vim and I’m interested how a “hardcore” ruby/rails coder has set up his vim. :-) Bye the way great post!
” I then review the changes and, if they rock, either rebase or merge them back into master.”
Just out of curiosity, what’s your decision criteria for performing a rebase vs. a merge? (if you don’t mind me asking)
Cool. I better start backing up my dotfiles. A little shortcut in your script: you have access to all your environment variables, so you can use ENV[‘HOME’] instead of running File.expand_path on ~.
Surely your joke works better as ‘Shirley’ =]
sweeeeeeeeeeeeet dot file’n
I made my installer verbose on what’s getting installed and put ln into interactive mode with -1
http://pastie.org/195177
yes defunkt, share your vimrc
Why not use http://code.google.com/p/js-hotkeys/? It’s a jquery plugin and supports complex hotkeys like ‘Ctrl+g’ and ‘f1’
Good call about keeping your dotfiles in version control. I’ve been doing it for years, and it’s always surprised me how many hackers don’t do this. Seems essential to me.
Anyway, I’ve always just added the files directly rather than jumping through the symlink hoops. I’d recommend this—rest assured that it works perfectly well and ends up being a good bit simpler. The only downside is that you have to be slightly smarter about your .gitignore file: http://github.com/technomancy/dotfiles/tree/master/.gitignore
Why don’t you make your dotfiles repo public? I am f’sure it would be helpful.
For keep your dotfiles in Git, In third step, pastie code assumes project is initiated with git. In fourth step you are doing git init. git init should be done before running pastie code.
Regarding the dotfiles: I changed this a little
You can keep your dot files a lot easier by just doing git init on your home directory, adding a .gitignore that ignores everything and then doing git add -f to whatever files you want to use. I’ve been doing this with Subversion for years, and moved it to git a few months ago.
Chime in.