5 ms·
Git alias for printing recently-used branches
- petepete 6y agoI 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
- montroser 6y agoYes, 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.
- jkubicek 6y agoI 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.
- sixstringtheory 6y agoI've got one really close to this: git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short) %(committerdate:short) %(upstream:remoteref)' | column -t
- alkonaut 6y agoThis is much better as it’s portable and doesn’t cheat by assuming awk/grep/etc are available.
- mandelbrotwurst 6y agoHonest question, what kind of environments are you working in where you don't / can't have these?
- alkonaut 6y agoWindows (cmd/powershell). It wouldn’t surprise me if windows cmd is the most common environment for git on command line, since windows is the most common OS among developers (and git-bash is terrible).
- deleted 6y ago[deleted]
- telekid 6y agoWhat about just `git reflog`? Then, you get to see recent branches _and_ you get additional context about what you were doing at the time.
- STRML 6y agoEven better, `tig reflog`, which makes it easy to check out the content of a commit or the history of a branch in context with the reflog.
- floatingatoll 6y agoI 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 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).
- mpawelski 6y agoI 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 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.
- Firehawke 6y agoIt doesn't seem to be dead. There was a PR commit only a week ago. You probably should poke the author again.
- ryanpetrich 6y agoAnother option: git log --all --author=`git config user.email` --oneline --decorate
- jph 6y agoI alias `git ref-recent` to: git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short) %(objectname:short) %(contents:subject)' refs/heads/ The output shows the date, branch name, commit hash, and commit subject, such as: 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 I put my aliases in GitAlias, which has many more: https://github.com/gitalias/gitalias https://github.com/gitalias/gitalias
- grumple 6y agoI use this: git for-each-ref --sort=authordate --format '%(authordate:iso) %(align:left,25)%(refname:short)%(end) %(subject)' refs/heads The most recent branches will appear closest to your cursor (on the bottom).
- kbd 6y agoEven better, show your local/remote branches in most-recent order and interactively pick the branch to switch to using fzf: https://github.com/kbd/setup/blob/f3ebd5ef2bc8a010357b574c02ecf5f8f1c2886a/HOME/.config/git/config#L67 https://github.com/kbd/setup/blob/f3ebd5ef2bc8a010357b574c02...
- jamesgeck0 6y agoThat's the way to go! [alias] rb = for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ --count=10 To switch branches, I invoke this from a shell script and type a couple characters from a branch name git checkout (git rb|fzf)
- alpb 6y agoI alias `gbv` to this which shows you commit hash, msg, ID, author, date with colors: alias gbv="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objec tname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"
- jilles 6y agoBeen using this snippet from Paul Irish for years: https://github.com/paulirish/git-recent https://github.com/paulirish/git-recent
- amarshall 6y agoSo 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. 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. Maybe someone will find it useful as I have. https://github.com/amarshall/git-recent-branches https://github.com/amarshall/git-recent-branches
- memco 6y agoNeat! This was a feature I requested in Fork[0], but wasn't sure such a thing was even possible. [0] https://git-fork.com https://git-fork.com
- whalesalad 6y agoI’ve got something similar, but it’s color coded and has columns with more info. https://github.com/whalesalad/dotfiles/blob/master/zsh/git.zsh#L12 https://github.com/whalesalad/dotfiles/blob/master/zsh/git.z...
- bhaak 6y agoI made a small script that outputs local and/or remote branches color coded: https://i.imgur.com/QkmPhm0.png https://i.imgur.com/QkmPhm0.png https://github.com/bhaak/dotfiles/blob/master/git/git-overview-branches https://github.com/bhaak/dotfiles/blob/master/git/git-overvi... It has been so useful to me that I think I should extract it from my dotfiles repository and give it its own repository. Or reimplement it in Rust as a introductory programming project.