Endless Parentheses

Ramblings on productivity and technical subjects.

profile for Malabarba on Stack Exchange

It’s Magit! And you’re the magician!

There’s nothing I can praise about Magit that hasn’t been written in a dozen blogs already, but since Jonas started a kickstarter campaign for it I knew I had to say something. If you use Magit, you already know the greatness of it. And if you don’t, hopefully I can convince you to try it in time to back the campaign.

I could go on and on about the virtues of this gem. It’s probably the package that most saves me time, and has taught me more about git than I learned reading a whole book on it. But that’s all just sparks and glitter on top of the real show. For Magit is a magic show, and its real feature is making you the magician.

Controlling Magit feels like putting on a performance. Move your fingers quickly enough, and you’ll be rebasing faster than the eye can see. But if your crowd is not impressed yet, you move on to tagging, cherry-picking, rewriting, reflogging until they’re left staring unblinkingly at your monitor, their jaws unknowingly open in awe.

But, if you’re one of those that only cares about practical benefits, then here are few Magit commands I use just about everyday.

f a Fetch all remotes
Usually how I start my day. Updates information about all remote branches, without messing with your local branch. Really helps that it’s a one-handed combo, so I can do it while sipping the morning coffee.
r u Rebase upstream
Upstream usually means origin/master. If fetch-all indicates that my local branch is out of date with upstream, this will quickly bring it up to date. If I don’t want to rebase this branch, I can m m and merge instead. Since fetch-all has already done all of the slow networking, both merge and rebase are super quick.
b s Branch spin-off
Creates and checks out a new branch, while carrying over any ongoing (and possibly committed) changes. It even undoes the commits on the previous branch. Super useful if you realise you forgot to branch-off from master before starting to work.
b c Branch create
Over time I’ve been gradually using less b s and more b c. When I need a new working branch, instead of having to switch to master, pull origin, and then spin-off, I simply b c straight from origin/master (it never really matters if my local master is outdated).
P … Push!
Feels silly that pushing is so far down my list, but here you go. P p is 95% of my usage, but P t is also useful and you’ll occasionally need a -f in there.
c … Commit powers
c c is your basic commit. But I couldn’t live without c w (for quickly fixing a commit message) or c e (for throwing more changes into the last commit).
l l Log current
Magit is pretty good at keeping you informed of the commit difference between local and remote, but l l is a quick way to get your bearings if you ever feel lost.
y Branch viewer
Concise list of all refs. Great for finding and removing old branches with k (both local and remote). Magit even warns if you try to delete a branch that isn’t merged.

And a few commands I don’t really use everyday, but rather eagerly look forward to the next chance to use them.

l r Reflog
Don’t know what reflog is? Neither did I! Magit taught me about reflog without saying a word, and you should learn it too (it feels like a superpower).
r s Rebase subset
At work, when I need to hotfix something I branch-off from origin/production instead of origin/master. Occasionally though, I’ll forget to do that, commit my hotfix, only to realise my branch is now 100 commits ahead of production. Rebase subset solves this is a blink, by taking only the commit I want and placing it on top of another branch.
r i Rebase interactively
I admit, I was a little scared when I first tried this feature. I had no idea what it did, but that “interactively” menu option had been teasing me for months. If I explain it here I feel like I’d be robing you of the discovery, so I’ll just describe it as “omnipotence over history”.

All of this arsenal combines into some fast and powerful git manipulation. Just yesterday a colleague asked for help on one of his branches. The whole checkout, edit, commit, push process took less than 30 seconds. One more b b and I was back in my branch doing my own stuff.

What’s more, it all feels right. My editor is where I manipulate the source code, that’s where I ought to be changing branches, not alt-tabbing to a terminal.

comments powered by Disqus