Live data from Hacker News

Git alias for printing recently-used branches

ses4j.github.io

1–10 of 25 posts

Re: Git alias for printing recently-used branches

#2
I alias 'git recent' to:

    git branch --sort=-committerdate -v
It gives me the following output (first line for not actually included):

    [branch name]                                      [hash]  [commit message header]
    move-radio-and-checkbox-hints-up                   9dff690 Move the hints belonging to radios/checkboxes up
    update-rubocop                                     8cace1f Update rubocop and pry, fix some new offences
    fix-remaining-injected-content-placement           48dc51d Reorder elements of other inputs

Re: Git alias for printing recently-used branches

#3
post #2

I alias 'git recent' to: git branch --sort=-committerdate -v It gives me the following output (first line for not actually included): [branch name] [hash] [commit message header] move-radio-and-checkbox-hints-up 9dff690 Move the hints belonging to radios/checkboxes up update-rubocop 8cace1f Update rubocop and pry, fix some new offences fix-remaining-injected-content-placement 48dc51d Reorder elements of other inputs

Yes, my "see what the team is up to" git command is:

    git branch -a --sort=-committerdate
That's short enough for my taste not to have to alias, and it gives output more or less similar to GitHub's "Active branches" view.

Re: Git alias for printing recently-used branches

#4
post #2

I alias 'git recent' to: git branch --sort=-committerdate -v It gives me the following output (first line for not actually included): [branch name] [hash] [commit message header] move-radio-and-checkbox-hints-up 9dff690 Move the hints belonging to radios/checkboxes up update-rubocop 8cace1f Update rubocop and pry, fix some new offences fix-remaining-injected-content-placement 48dc51d Reorder elements of other inputs

I do the same thing for this slightly longer alias

    git for-each-ref --sort=-committerdate --format='%(committerdate:short): %(refname:short)' refs/heads/
Including the dates is crucial; I'll frequently go in and clean up personal branches that are older than X months.

Re: Git alias for printing recently-used branches

#6
post #2

I alias 'git recent' to: git branch --sort=-committerdate -v It gives me the following output (first line for not actually included): [branch name] [hash] [commit message header] move-radio-and-checkbox-hints-up 9dff690 Move the hints belonging to radios/checkboxes up update-rubocop 8cace1f Update rubocop and pry, fix some new offences fix-remaining-injected-content-placement 48dc51d Reorder elements of other inputs

This is much better as it’s portable and doesn’t cheat by assuming awk/grep/etc are available.

Re: Git alias for printing recently-used branches

#8
I shared this with a coworker, who discovered that it dumps information about branches that don't exist anymore. This comment's alternate command doesn't list deleted branches:

https://news.ycombinator.com/item?id=22797911

And for those wondering "deleted branches?", check the git-gc man page for gc.reflogexpire (default 90 days) and gc.reflogexpireunreachable (default 30 days).

Re: Git alias for printing recently-used branches

#9
I had idea to add something similar as tab completion to posh-git module for Powershell. Sadly it was not merged (is posh-git dead?) https://github.com/dahlbyk/posh-git/pull/641

I wonder if something similar can be done in bash? By default bash doesn't "cycle" through possible completion but just display the list. Still, I guess it would be usefull to display last used branches first.

Post reply on HN