TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Git alias for printing recently-used branches

96 pointsby ses4jabout 5 years ago

14 comments

petepeteabout 5 years ago
I alias &#x27;git recent&#x27; to:<p><pre><code> git branch --sort=-committerdate -v </code></pre> It gives me the following output (first line for not actually included):<p><pre><code> [branch name] [hash] [commit message header] move-radio-and-checkbox-hints-up 9dff690 Move the hints belonging to radios&#x2F;checkboxes up update-rubocop 8cace1f Update rubocop and pry, fix some new offences fix-remaining-injected-content-placement 48dc51d Reorder elements of other inputs</code></pre>
评论 #22797911 未加载
评论 #22797584 未加载
评论 #22797988 未加载
amarshallabout 5 years ago
So many commenters here providing alternatives seem to miss the key differentiating feature: recently checked out vs. recently committed to. For me the former is immensely more useful as I may have gone to a branch to do something other than commit, and those are missed with the latter.<p>Anyway, I’ve had my own (far more involved) version of listing recently checked-out branches for years. It will also filter out the current branch and deleted branches, and has a rudimentary interactive selection.<p>Maybe someone will find it useful as I have.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;amarshall&#x2F;git-recent-branches" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;amarshall&#x2F;git-recent-branches</a>
telekidabout 5 years ago
What about just `git reflog`? Then, you get to see recent branches _and_ you get additional context about what you were doing at the time.
评论 #22798872 未加载
floatingatollabout 5 years ago
I shared this with a coworker, who discovered that it dumps information about branches that don&#x27;t exist anymore. This comment&#x27;s alternate command doesn&#x27;t list deleted branches:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22797911" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22797911</a><p>And for those wondering &quot;deleted branches?&quot;, check the git-gc man page for gc.reflogexpire (default 90 days) and gc.reflogexpireunreachable (default 30 days).
kbdabout 5 years ago
Even better, show your local&#x2F;remote branches in most-recent order and interactively pick the branch to switch to using fzf:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;kbd&#x2F;setup&#x2F;blob&#x2F;f3ebd5ef2bc8a010357b574c02ecf5f8f1c2886a&#x2F;HOME&#x2F;.config&#x2F;git&#x2F;config#L67" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kbd&#x2F;setup&#x2F;blob&#x2F;f3ebd5ef2bc8a010357b574c02...</a>
评论 #22799561 未加载
jphabout 5 years ago
I alias `git ref-recent` to:<p><pre><code> git for-each-ref --sort=-committerdate --format=&#x27;%(committerdate:short) %(refname:short) %(objectname:short) %(contents:subject)&#x27; refs&#x2F;heads&#x2F; </code></pre> The output shows the date, branch name, commit hash, and commit subject, such as:<p><pre><code> 2020-04-06 master d8560f4 Add feature foo 2020-03-28 fix-button 15f985d Fix button for menu 2020-03-19 optimize-sort 3dbec4d Optimize sort algorithm </code></pre> I put my aliases in GitAlias, which has many more: <a href="https:&#x2F;&#x2F;github.com&#x2F;gitalias&#x2F;gitalias" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gitalias&#x2F;gitalias</a>
bhaakabout 5 years ago
I made a small script that outputs local and&#x2F;or remote branches color coded: <a href="https:&#x2F;&#x2F;i.imgur.com&#x2F;QkmPhm0.png" rel="nofollow">https:&#x2F;&#x2F;i.imgur.com&#x2F;QkmPhm0.png</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;bhaak&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;git&#x2F;git-overview-branches" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bhaak&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;git&#x2F;git-overvi...</a><p>It has been so useful to me that I think I should extract it from my dotfiles repository and give it its own repository.<p>Or reimplement it in Rust as a introductory programming project.
mpawelskiabout 5 years ago
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?) <a href="https:&#x2F;&#x2F;github.com&#x2F;dahlbyk&#x2F;posh-git&#x2F;pull&#x2F;641" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dahlbyk&#x2F;posh-git&#x2F;pull&#x2F;641</a><p>I wonder if something similar can be done in bash? By default bash doesn&#x27;t &quot;cycle&quot; through possible completion but just display the list. Still, I guess it would be usefull to display last used branches first.
评论 #22801122 未加载
memcoabout 5 years ago
Neat! This was a feature I requested in Fork[0], but wasn&#x27;t sure such a thing was even possible.<p>[0] <a href="https:&#x2F;&#x2F;git-fork.com" rel="nofollow">https:&#x2F;&#x2F;git-fork.com</a>
alpbabout 5 years ago
I alias `gbv` to this which shows you commit hash, msg, ID, author, date with colors:<p>alias gbv=&quot;git for-each-ref --sort=committerdate refs&#x2F;heads&#x2F; --format=&#x27;%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objec tname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))&#x27;&quot;
whalesaladabout 5 years ago
I’ve got something similar, but it’s color coded and has columns with more info.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;whalesalad&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;zsh&#x2F;git.zsh#L12" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;whalesalad&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;zsh&#x2F;git.z...</a>
grumpleabout 5 years ago
I use this: git for-each-ref --sort=authordate --format &#x27;%(authordate:iso) %(align:left,25)%(refname:short)%(end) %(subject)&#x27; refs&#x2F;heads<p>The most recent branches will appear closest to your cursor (on the bottom).
jillesabout 5 years ago
Been using this snippet from Paul Irish for years: <a href="https:&#x2F;&#x2F;github.com&#x2F;paulirish&#x2F;git-recent" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;paulirish&#x2F;git-recent</a>
ryanpetrichabout 5 years ago
Another option:<p><pre><code> git log --all --author=`git config user.email` --oneline --decorate</code></pre>