Git tricks


Posted on 19 May 2014 by jose

I've been usin' Git at work exclusively fer a while now (like on Hackwater, we've finally moved off o' Subversion), an' I just want t' leave a note t' meself outlinin' some o' th' useful thin's I've come across.

Startin' with git config, I like t' enable color an' credentials (fer temporary passwordless Github auth). Also, with nearly 40 git repos, havin' a global ignore list is incredibly useful. I'm still tryin' t' decide on git aliases that I like; I'll maybe do another post when I've definitively come down on those.

I can't express me love fer Git's cheap branchin' model enough. Ye'll be sleepin' with the fishes! With tools like th' (hopefully seldom used) git cherry-pick an' git rebase (an' th' scary interactive rebase), me local branch garden is well-kept, Ya horn swogglin' scurvy cur, yo ho, ho git reset is great at revertin' un-pushed but committed changes, as well as lettin' ye set HEAD t' a particular point in time (more history manipulation).

I'm still decidin' on a workflow I like, an' 'tis possible that I may use more than one dependin' on a project. I initially liked th' git-flow workflow I saw on nvie.com, but I'm also a fan o' Github's workflow. As a Drupal consumer an' occasional contributor, I've also read an' enjoyed Randy Fay's thoughts on a rebase workflow.

For miscellaneous commands, I like git add --patch (or -p) fer when I'm workin' two different issues in one file. git clean keeps me workin' copy neat. Yaaarrrrr! And swab the deck! git filter-branch is another one o' those history re-writin' tools (fer me, anyway) that I've mostly used t' remove large binary files from th' repo/index; if ye have a lot o' medium-t'-large binaries in version control (a bad thin' in me opinion), an' ye have th' opportunity t' move them t' a CDN or at a minimum, outside o' th' repo, it makes code deployments much faster if ye can filter those large files out o' th' repo as if they had not existed in th' first place. Use carefully (an' like th' filter-branch manual says, take a look at th' BFG fer mass cleans).

git filter-branch works best on a clone o' a repo, as it gives ye a chance not t' trash yer main workin' copy until ye push an' pull. Be absolutely certain ye're ready t' push, an' then take advantage o' th' --prune=now an' other git gc options, an' t' expire yer reflog first.

Latest poll

Which do you favor?

Choices

Twitter