What git ls-remote
does is call up the other Git—the one at the URL you see above—and ask it about its references: HEAD
, branch names, tag names, and so on. But the only information that it sends are those names and the hash IDs.
As I noted in comments above, each commit—represented by a hash ID, which is sort of the commit's true name—has two timestamps in it.1 To obtain either or both time stamp, you must have the commit. So this means git ls-remote
is not sufficient in general: you might not have the commits whose hash IDs you get from the other Git.
What you need to run first is git fetch
, which starts the same way: it calls up some other Git and gets from it a list of their branches, tags, etc., and the hash IDs that each of those names represent. Then, for their branches, your Git will create or update your remote-tracking names: their master
becomes your origin/master
, for instance. Their develop
becomes your origin/develop
. Whatever names they have—refs/heads/*
being the full form—your Git creates or updates your own corresponding refs/remotes/origin/*
name. But before your Git can do that, your Git must obtain the commits themselves as well, so for any commits they have that you don't, that your Git needs, your Git gets those.
You may want to add --prune
(git fetch -p
for short) to direct your own Git to delete any remote-tracking name you have now that no longer corresponds to a branch in their Git. If you don't, you'll keep stale remote-tracking names forever (or until you explicitly prune them). This isn't really harmful so much as clutter-y.
Now you have all of their commits, plus any of your own you have not sent. You also have all of their names, changed into your remote-tracking names.
You can view these branches with git branch -r
. The default sort order for git branch
is alphabetic-within-group.2 But you can give a --sort=key
option:3
git branch -r --sort=authordate
or:
git branch -r --sort=committerdate
which will sort based on the corresponding time stamp stored in the commit to which each remote-tracking name points.
Hence:
git fetch -p
git branch -r --sort=committerdate
should get you what you want (unless you want author date; see footnote 1).
(Aside: I like to configure fetch.prune
to true
in my per-user configuration, so that all fetches act like git fetch --prune
always.)
1The two timestamps are the author timestamp and the committer timestamp. In many cases, both hold the same date-and-time anyway. A new commit in general gets both the same, and then if you copy the commit to a new and improved one, via git commit --amend
or git rebase
or any of the many other ways that can do that, the new and improved commit has the old commit's author information, and you-and-now as the committer information.
2Technically, it's more ASCII-betic, or UTF-8-betic, than alphabetic: a digit comes before uppercase, and uppercase comes before lowercase.
3Your git branch
needs to be new enough to have the --sort
option, which was introduced to git branch
in Git 2.7. If your Git is older, consider using git for-each-ref
.