How can I list all branches that contain commits newer than a specific date?

When using git log, I can supply --since=<date> to limit the log to commits newer than a certain date.

With git branch -r, I get all the remote branches.

  • Should Gemfile.lock be included in .gitignore?
  • Error in running 'git apply'
  • Git Giving “fetch first” error when trying to push
  • Visual Studio to GitHub
  • Problems SourceTree listing files in local repository as deleted
  • Invalid SSL certificate when pushing to Git server
  • How would I get the list of branches that have contributions that are younger than a given date, i.e. all branches that contain commits newer than the date I’m interested in?

    Alternatively, if that is hard or not possible, respecting only the date of the branch’s tip might be sufficient.

  • Are there tools for managing large binary files in git on Windows?
  • Neat, clean compacted git PR and merge commit, into one commit
  • What's the purpose of forking a git repo?
  • In Git for Windows Bash, how to install “get-apt” and “sudo” and all those basic commands?
  • How can I archive old git tags?
  • git checkout origin/master doesn't work?
  • 3 Solutions collect form web for “How can I list all branches that contain commits newer than a specific date?”

    How would I get the list of branches that have contributions that are younger than a given date, i.e. all branches that contain commits newer than the date I’m interested in?

    Here is one possible approach: use git for-each-ref to run

    git log -1 --since=<date> <branch>
    

    for each of the branch references in your repo. If the output of this git log command is non-empty, then the branch in question contains commits newer than <date>, and you should print the branch’s name in your list; otherwise, it does not, and you shouldn’t print its name.

    Here is a shell script that takes one argument, which should be a string that Git can recognize as a date (such as 2014/12/25 13:00, 3.months.ago, yesterday etc.), and lists all the “green branches” (for lack of a better term), i.e. local branches that contain commits newer than the specified date.

    #!/bin/sh
    
    # git-greenbranch.sh
    #
    # List the local branches that contain commits newer than a specific date
    #
    # Usage: git greenbranch <date>
    #
    # To make a Git alias called 'greenbranch' out of this script,
    # put the latter on your search path, and run
    #
    #   git config --global alias.greenbranch '!sh git-greenbranch.sh'
    
    if [ $# -ne 1 ]
    then
        printf "usage: git greenbranch <date>\n\n"
        printf "For more details on the allowed formats for <date>, see the\n"
        printf "'git-log' man page.\n"
        exit 1
    fi
    
    testdate=$1
    
    git for-each-ref --format='%(refname:short)' refs/heads/ \
        | while read ref; do
              if [ -n "$(git rev-list --max-count=1 --since="$testdate" $ref)" ]
              then
                  printf "%s\n" "$ref"
              fi
          done
    
    exit $?
    

    (The script is available at Jubobs/git-aliases on GitHub.)

    For convenience, you can define, at the user level, a Git alias (called greenbranch.sh, here) that runs the script in question:

    git config --global alias.greenbranch '!sh git-greenbranch.sh'
    

    Make sure the shell script is on your path.

    Tests in a clone of the Git-project repo

    $ git clone https://github.com/git/git/
    # go grab a cup o' coffee...
    
    $ cd git
    
    # check all remote branches out (for testing purposes)
    $ git checkout -b maint origin/maint
    $ git checkout -b next origin/next
    $ git checkout -b pu origin/pu
    $ git checkout -b todo origin/todo
    
    $ git greenbranch "yesterday"
    maint
    master
    next
    pu
    todo
    $ git greenbranch "today"
    $
    

    This shows that all five branches contain commits made “yesterday”, but none contain commits made “today”.

    --simplify-by-decoration lists only commits that have a direct reference:

    git log --oneline --decorate --branches --remotes --since=$date \
            --simplify-by-decoration
    

    from there it’s just a question of formatting.

    You can show the date of the most recent commit on some-branch using

    git log -1 --format=format:%cd some-branch
    

    This date can be printed in different formats as well, see the --date option on the git log man page.

    Git Baby is a git and github fan, let's start git clone.