Git branches with recent activity
November 5, 2019
There is a long running repository of a project that's much larger than I want or need. I shallow cloned the last few months but did not use --no-single-branch, so my local repo only knows about origin/master and I can't checkout any other branches.
From How do I "undo" a --single-branch clone? I know I can get ALL branches , or add one at a time .
ALl includes dozens of branches I don't need to know about and downloads too many MB. 1 at a time is a bit of pain.
My question is, how can I add all branches which have had activity in last x months (or x *100 commits) -- and skip everything else?
How can I get a list of Git branches, ordered by most recent commit? sorts branches by date, but doesn't work from shallow clone. Is there some way to get this list from GitHub instead from git itself? (Since that seems to require downloading everything.)
Here's a hack job, a demonstration of how one shouldn't do it because it doesn't use the API. However with this you don't need an API key so the incantation can be used by anyone. [β¦]
export URL=https://github.com/leo-editor/leo-editor/branches/active
curl $URL > x.html
printf '\n-- Commands to add the remote branches to the fetch list:\n'
grep 'data-branch-name' x.html | sed -r 's/^.*data-branch-name="(.*?)"(.*$)/git remote set-branches --add origin \1/'
printf '\n-- Modification dates for these branches:\n'
grep 'time-ago' x.html | sed -r 's/^.*datetime="(....-..-..).*$/\1/'
From < https://gist.github.com/maphew/1b706e66e87919dbd2538f21b6ea9f26 >
Git branches with recent activity#
List branches in table with dates first
git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
2019-11-01 devel
2019-11-01 clean-up-root
2019-08-28 pyzo
2019-08-27 desktop-links
2019-08-26 gui
2019-08-02 master
2019-05-29 dock
2019-05-03 mhw-versions
2019-04-30 py3
2018-12-05 skeleton
2018-10-18 setup-968
2018-10-04 travis
Github Urls
You can click "Branches" in the repository. Or hit the URL directly: https://github.com/ORGANIZATION_NAME/REPO_NAME/branches
https://github.com/leo-editor/leo-editor/branches/active
https://github.com/leo-editor/leo-editor/branches/all
The API is the clean way to from command line, but requires authentication, so the script or cmd snippet can't be easily shared.
$ grep 'data-branch-name' test.html
<li class="Box-row d-flex js-branch-row flex-items-center Details position-relative" data-branch-name="fstrings">
<li class="Box-row d-flex js-branch-row flex-items-center Details position-relative" data-branch-name="names">
<li class="Box-row d-flex js-branch-row flex-items-center Details position-relative" data-branch-name="devel">
<li class="Box-row d-flex js-branch-row flex-items-center Details position-relative" data-branch-name="clean-up-root">
<li class="Box-row d-flex js-branch-row flex-items-center Details position-relative" data-branch-name="6.1-b1-rel">
$ grep 'time-ago' test.html
Updated <time-ago datetime="2019-11-05T18:16:24Z" class="no-wrap">Nov 5, 2019</time-ago> by <a class="muted-link" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=592928" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="#root/9m1p4HOarDPy">edreamleo</a>
Updated <time-ago datetime="2019-11-04T23:39:00Z" class="no-wrap">Nov 4, 2019</time-ago> by <a class="muted-link" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=592928" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="#root/9m1p4HOarDPy">edreamleo</a>
Updated <time-ago datetime="2019-11-04T23:39:00Z" class="no-wrap">Nov 4, 2019</time-ago> by <a class="muted-link" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=592928" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="#root/9m1p4HOarDPy">edreamleo</a>
Updated <time-ago datetime="2019-11-01T19:47:55Z" class="no-wrap">Nov 1, 2019</time-ago> by <a class="muted-link" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=486200" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="#root/ZL9rQvEkVur6">maphew</a>
Updated <time-ago datetime="2019-10-27T10:35:14Z" class="no-wrap">Oct 27, 2019</time-ago> by <a class="muted-link" data-hovercard-type="user" data-hovercard-url="/hovercards?user_id=592928" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="#root/9m1p4HOarDPy">edreamleo</a>
mleo</a>
List only branch names
$ grep 'data-branch-name' test.html | sed -r 's/^.*data-branch-name="(\w)/\1/' | sed 's/">//'
fstrings
names
devel
clean-up-root
6.1-b1-rel
List modified times
$ grep 'time-ago' test.html | sed -r 's/^.*datetime="(....-..-..).*$/\1/'
2019-11-05
2019-11-04
2019-11-04
2019-11-01
2019-10-27