Join the discussion
Write your take first — we'll ask for email only when you're ready to publish.
- Hacker News
- I made a lovely little TUI for this, with Charm (https://charm.sh)
https://github.com/tyre/recent-branches
Enjoy!
by tyre - Here is a much, much, much lighter weight version I've been using since forever:
fzf handles the TUI partgi() { git branch --sort=-committerdate |\ grep -v '^\*' | cut -d' ' -f3 | fzf |\ xargs git checkout }by petesergeant - I wonder about the "modern" git part. Here is how to do it in 2013: https://stackoverflow.com/a/10693888/2361979by qznc
- I love this little fzf bash function that I wrote a few years ago: https://gist.github.com/thomasaarholt/141df779f3f16b641701b4...
It opens a fuzzy finder window showing the branches you have in the repo, sorted by recency. Also shows the latest committer and the date. Hit enter on the one you want to swap to it.
by tomtom1337 - I have been using something like this for 10+ years by this point - still wonder why it is not default or easier to do than a custom gitconfig/alias hack. :Pby m4rtink
- Git defaults are a bit weird. You also have to enable rerere yourself, when it should be on by default.by eru
- Probably because most of the time you list branches you goal isn't to discover what exists, but to find the specific one you're looking for.by dataflow
- > Just configure git branch to sort by the last commit date:
> git config branch.sort committerdate
> You can also supply this on a one-off basis as git branch --sort committerdate.
These don't seem like hacks to me. What do you have in mind?
by fwip - I rarely care about the date of the commit on the branch to determine recency, I care about when I last switched to the branch.
This comment gets it correct https://news.ycombinator.com/item?id=49504860
I wrote my own version to do this nearly 10 years ago: https://github.com/amarshall/git-recent-branches
by amarshall - There's a bunch of these good ideas here: https://news.ycombinator.com/item?id=43169435by krautsauer
- Our team's `git branch` output is a graveyard. Sorting by last commit would be a godsend for quickly identifying active work and stale branches.by dalton74
- When I'm working on a repository where the remote is shared (like a corporate GitHub repository where not everyone has their own GitHub fork) I tend to name all my branches like 'eru/<something>'. That way I can quickly find my work, and I can also confidently delete branches without worrying about stepping on other people's toes nor being stepped on by accident. I encourage co-workers to do the same, but haven't strictly required it from team members.by eru
- I have been using the `git lb` alias suggested by https://ses4j.github.io/2020/04/01/git-alias-recent-branches... (post written April 1st but not a joke) and quite enjoying it. Shows me the last 10 branches I worked on (very easy to edit the alias definition to get more or fewer than 10), sorted by date, most recent first. It's been handy in all sorts of situations, especially because one of our internal libraries needs a bugfix or a new feature every 3 months or so. So every time I cd into that repo, I have no clue what I did last, but `git lb` tells me right away.by rmunn
- The best upgrade to these kinds of git branch scripts is piping them to fzf. I’ve been using this fbr one from the fzf repo. https://github.com/jbranchaud/dotfiles/blob/main/zshrc.local...by jbranchaud
- Huge fan of `git recent` [0] for this purpose.by metmac
- Spoiler it’s fzf under the hood. But it’s perfect and simple.by metmac
- FYI/fwiw Fish shell autocompletes branches sorted by last commit date when writing out git commands. It also provides completions for commitish objects grouped by class, giving precedence to the usual targets first, with each group sorted by its own sort key. Handy!by ComputerGuru
- Every day, I learn a cool new thing that fish can doby yonatan8070
- Even better (IMHO!) is `git config branch.sort -committerdate` (note the `-`). This will sort newest committer date first.by asb
- Even better, "hey, chat GPT, list my branches by commit date."
I know that's not a popular answer, but I'm just trying to demonstrate the reality that this kind of knowledge isn't specialized anymore.
by johnwheeler - I have this as an alias in my .zshrc!! Very handyby pkaodev
- Rebase an old branch and it suddenly looks recent again. The rewritten tip gets a fresh committer date.by nulltrace
- `git config --global branch.sort -committerdate`by mmsc