How to get all branches with someone’s commits using git?

How can I get the names of all branches that someone made a commit to in the last month?

  • Ignoring Hidden Files git
  • Rebase/Replay Merge Commits Only
  • Attempting to merge branches returns 'already up to date' despite there being changes
  • How to exclude from Git tracking (after the fact)?
  • Gerrit: ! HEAD -> refs/publish/master (no new changes)
  • What is a patch in git version control?
  • Eclipse Luna file names not shown in GIT Commit Changes dialogue
  • How to use Vim to quickly see Mercurial or Git changes
  • Git pull hangs on SMB shared repository
  • synchronizing files with server using git
  • How to review merge commits to detect incorrect hunks
  • Unable to install Gerrit's commit-msg hook; authentication seems fine
  • 5 Solutions collect form web for “How to get all branches with someone’s commits using git?”

    Disclaimer: This is not a full-baked answer, just an idea.

    A little technical background before the actual answer.

    A Git branch is just a pointer to a commit. It can change from one history branch to another and, apart from an entry in the branch’s reflog (if it is enabled), the movement of a branch doesn’t leave any trace in the repository.

    To make it clear, let’s say the repo looks like this:

                   +-- branch X
    A -- B -- C -- D 
            - E -- F
                   +-- branch Y

    This simple sequence of commands:

    git checkout X
    git reset --hard F
    git checkout Y
    git reset --hard D

    makes branches X and Y swap their places. Now the repository looks like this:

                   +-- branch Y
    A -- B -- C -- D 
            - E -- F
                   +-- branch X

    The commit E, for example, now belongs to branch X and cannot be reached from branch Y but it belonged to branch Y (and couldn’t be reached from branch X) when it was created.

    This makes your question indeterminate.

    The answer

    The command to use is git log with some parameters:


    Show commits more recent than a specific date.


    Show commits older than a specific date.


    Limit the commits output to ones with author/committer header lines that match the specified pattern (regular expression).


    Pretend as if all the refs in refs/ are listed on the command line as <commit>.


    Instead of walking the commit ancestry chain, walk reflog entries from the most recent one to older ones.

    The command line should be something like this:

    git log --since='1 month ago' --all 

    You can put the complete name or email address of the author or just a fragment of it in the --author argument.

    --all tells git log to search the commits accessible using all the current branches

    If you add --walk-reflogs to the command line and replace --all with a specific branch name (f.e. Y in the example from the first part of this answer), Git follows the movement history of the Y branch (recorded in the reflog) and returns commits F, E, B and A. Without --walk-reflogs Git follows the commits accessible from the current position of branch Y and returns the commits D, C, B and A (assuming all of them match the other conditions).

    Be aware that adding --walk-reflogs can return incomplete results or nothing. The branch’s reference log contains the movement of the branch (because of commit, reset, rebase and other commands) on the local repository only, it can be disabled or cleared

    You can use the “–since” option to git log to select commits within the last month:

    git log --since="`date -d'1 month ago'`"

    Then for each of those revisions you can use “git branch –contains” to show which branches it was in. e.g:

    git branch --contains 00735a997d0bba684dbf62552eea83b9491ac26b

    You can put this all together in a single line which will do it all for you and de-duplicate the output:

    git log --since="`date -d'1 month ago'`" --format="%H" | while read i; do git branch --contains $i; done | sort -u

    Actually it is not possible.

    You can find out in which branches commits of a user are contained that have an author date within the last month or that have a commit date within the last month. Both is potentially not very accurate.

    What you cannot do is to determine to which branch a commit was made in Git. A Branch is just a post-it note on a commit that moves on to the next commit automatically if the branch is checked out. But you can peel-off the post-it and place it anywhere you like at any time. So you cannot determine to which branch a commit was done and as commit and author dates can be arbitrarily set you cannot even reliably use those dates.

    You can maybe do such a thing if you have strict commit policies and they are obeyed by all people.

    Is that enough: git branch -av? It also shows potential remote branches.
    -a stands for all, -v for verbose. See here for more details.

    Edit: I think this answer gives a good overview over further possibilities. However, the branch creator is not tracked. Depending on the question git blame file might be interesting…

    You can use since & untill flag to see the commits of a date range. And use author flag to filter the someone’s commits.

    $ git log --since=2.month.ago --until=1.month.ago --author=<user>    # relative time
    $ git log --since=2000-01-01 --until=2012-12-21 --author=<user>      # absolute

    Then if you want to know that which branch(es) contains a specific commit.

    $ git branch --contains <commit-sha>          # show the branch list(s) containing the commit 
    Git Baby is a git and github fan, let's start git clone.