diff --git a/README.md b/README.md index 3aec71c..16a9012 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_606 TILs and counting..._ +_607 TILs and counting..._ --- @@ -182,6 +182,7 @@ _606 TILs and counting..._ - [Resetting A Reset](git/resetting-a-reset.md) - [Show All Commits For A File Beyond Renaming](git/show-all-commits-for-a-file-beyond-renaming.md) - [Show File Diffs When Viewing Git Log](git/show-file-diffs-when-viewing-git-log.md) +- [Show List Of Most Recently Committed Branches](git/show-list-of-most-recently-committed-branches.md) - [Show The diffstat Summary Of A Commit](git/show-the-diffstat-summary-of-a-commit.md) - [Single Key Presses in Interactive Mode](git/single-key-presses-in-interactive-mode.md) - [Staging Changes Within Vim](git/staging-changes-within-vim.md) diff --git a/git/show-list-of-most-recently-committed-branches.md b/git/show-list-of-most-recently-committed-branches.md new file mode 100644 index 0000000..4d7992f --- /dev/null +++ b/git/show-list-of-most-recently-committed-branches.md @@ -0,0 +1,28 @@ +# Show List Of Most Recently Committed Branches + +The standard way to list your branches is with the `git branch` command. If +you use branches extensively for feature work and bug fixes, you may find +yourself overwhelmed by the list of branches trying to visually parse +through them for the one that you had worked on recently. + +With the `git for-each-ref` command, we can produce a better list of +branches. + +```bash +$ git for-each-ref --sort=-committerdate --count=10 --format='%(refname:short)' refs/heads/ +``` + +The command itself will iterate over all of the repository's refs and print +them out as a list. The `--sort=-committerdate` option will ensure that list +is sorted by refs mostly recently committed to. The `--count=10` option +limits the list output to 10 refs. The `format` flag cleans up the output a +bit, only showing the shortname of the ref. Lastly, the `refs/heads/` +argument ensures that only local refs are included in the output, thus +ignoring remote refs. + +The result is a list of local branches ordered by recency which generally +corresponds to relevance. + +See `man git-for-each-ref` for more details. + +[source](https://twitter.com/djm_/status/961289486721339392)