Git checkout by date gives you code main didn't have yet

Commits are dated when they were made, not when they reached main, so ask GitHub's push log what main pointed to instead.

Download for MacmacOSSend it to your Mac
Git checkout by date gives you code main didn't have yet
  • Even the top answer, git rev-list --first-parent --before, returned a commit main didn't have yet on 33 of 79 days in our repo.
  • A commit is dated when it was made, and a fast-forward merge puts a branch's commits on main's own line.
  • Copy a free script that asks GitHub's push log what main really pointed to, and merge with --no-ff from now on.

You ask git for main as it was on Tuesday. It hands you code that only reached main on Thursday, and nothing tells you.

We build Yappr with many Claude Code sessions at once, each on its own branch, merging back all day. So we checked git’s answer for every day from 25 August to 11 November against GitHub’s record of what main really pointed to.

Even the top answer was wrong on 33 of 79 days

Days it gave a commit main didn’t have yet

--before63 of 79
--first-parent33 of 79

CLAUDE.md on main, 28 September

--before175 KB
--first-parent175 KB
GitHub’s push log103 KB

The bare version you’ll see in many answers returned a commit main didn’t have yet on 63 days.

Terminal
git checkout $(git rev-list -1 --before="2026-09-28 23:59" main)

The accepted answer on Stack Overflow adds --first-parent. That halved the misses but didn’t end them: for 28 September both versions handed back a CLAUDE.md of 175 KB, when main’s was 103 KB.

A commit is dated when it was made, not when it reached main

--before looks at every commit main holds today and picks the newest one dated before your date. An agent’s commit from the 3rd, merged on the 10th, is still dated the 3rd. Ask about the 4th and you get it, six days early.

Any branch merged into main does this. Parallel agents just make a lot more of them: of the 3,799 commits on our main, at least 2,742 came in from other branches.

--first-parent breaks on a fast-forward

--first-parent follows main’s own line and skips what merges brought in. The top answer on Stack Overflow calls that “what you usually want”, and with a merge commit for every landing it is. If everything reaches main through GitHub’s Merge pull request button, which always makes one, you’re mostly fine.

But git merge fast-forwards when it can, and then the branch’s own commits become main’s line, dated when they were made. On 29 September a release branch landed that way. So for 28 September, --first-parent shows the release a day before main had it.

Ask the push log instead

Only the server knows when main moved. If your repo is on GitHub, it keeps that record: the Activity button on every repo, and the same list from its API, each push with its time and the commit it left main on. This free script reads it.

  1. From inside your clone, with the GitHub CLI signed in. Give a time: git reads a bare date as that day at the current clock time. Then check the time and repo it prints back, because git guesses at dates it half understands.
    Terminal
    curl -fsSL https://www.useyappr.com/blog/git-checkout-by-date/main-at.sh -o ~/main-at.sh
    git checkout "$(bash ~/main-at.sh '2026-09-28 23:59')"
  2. On our repo it prints this, and it’s the commit main really had.
    main-at.sh
    noanborel-dev/yappr main as of 2026-09-28 23:59 CEST: set by a push at 2026-09-27T17:39:17Z
    895bcaeead0a5ca99d38c0e59a69325537d1e331

The other answer you’ll find, main@{2026-09-28}, reads your own clone’s log: when you pulled, not when main moved. Git also expires those entries after 90 days by default.

Read the script first (it's 38 lines)
main-at.sh
#!/bin/bash
# main-at.sh: prints the commit a GitHub branch really pointed to at a given
# moment, read from GitHub's own push log (the repository's Activity view),
# not from commit dates. Reads only.
#
#   bash main-at.sh "2026-10-03 18:00"          # main, in your time zone
#   bash main-at.sh "2026-10-03 18:00" release  # another branch
#   git checkout "$(bash main-at.sh '2026-10-03 18:00')"
#
# Run it inside a clone of the repository. Needs the GitHub CLI (gh), signed in.
# From useyappr.com/blog/git-checkout-by-date
set -euo pipefail

when=${1:?Usage: bash main-at.sh "<date and time>" [branch]}
branch=${2:-main}
repo=$(gh repo view --json nameWithOwner -q .nameWithOwner)

# git reads the date the way --before does, in your time zone. It reads a word
# it doesn't know as "now", so that is refused unless you asked for now.
t=$(git rev-parse --since="$when"); t=${t#--max-age=}
now=$(git rev-parse --since=now); now=${now#--max-age=}
if [ "$t" -ge "$now" ] && [ "$when" != now ]; then
  echo "\"$when\" is in the future, or git couldn't read it as a date. Try \"2026-10-03 18:00\"." >&2; exit 1
fi

last=$(gh api --paginate "repos/$repo/activity?ref=refs/heads/$branch&per_page=100" \
  --jq ".[] | select((.timestamp | fromdateiso8601) <= $t) | [.timestamp, .activity_type, .after] | @tsv" \
  | sort | tail -n 1)

if [ -z "$last" ]; then
  echo "GitHub's log has no push to $branch at or before that time." >&2; exit 1
fi
read -r stamp kind sha <<<"$last"
if [ "$kind" = branch_deletion ]; then
  echo "$branch had been deleted by then ($stamp)." >&2; exit 1
fi
echo "$repo $branch as of $(date -r "$t" '+%Y-%m-%d %H:%M %Z' 2>/dev/null || date -d "@$t" '+%Y-%m-%d %H:%M %Z'): set by a $kind at $stamp" >&2
echo "$sha"

Keep main’s line honest from now on

Merge into main with --no-ffEvery landing becomes a merge commit dated the day it landed, so --first-parent stays right. git config merge.ff false makes it the default.
Tell your agentsIf they do the merging, one line in CLAUDE.md: Land work on main only with `git merge --no-ff`. Never push a branch onto main.

It only fixes history from today. For anything older, the push log is the only answer.

We found this charting our own CLAUDE.md, which reached 681 KB: that chart is redrawn from the push log now. And when you run this many agents, one of them is always waiting on you: make your Mac turn red when it does.

How we measured, and what we didn't test

Our repo, on GitHub, with git 2.50.1. For each day from 25 August to 11 November 2026 at 23:59:59 UTC, we ran git rev-list -1 --before on main, with and without --first-parent, and compared it with the commit GitHub’s push log had main on at that moment. “Didn’t have yet” means the answer wasn’t an ancestor of that commit. Where both exist, from 13 October, the push log matched this Mac’s own record of origin/main entry for entry.

Not tested: GitLab or Bitbucket (they have their own logs; we didn’t read them), a repo that only squash-merges, and how far back GitHub keeps the log (ours went back to the repo’s first push in April; GitHub’s docs don’t say). Files: the script and a throwaway repo that shows both failures in a temp folder. Read the same day: git rev-list, gitrevisions, GitHub’s activity view and the Stack Overflow answer.

Written 12 November 2026. Every fact about another product is from its own pages, checked that day.