Answers: <p><em>Note: this answer shows how to find branches that have been *updated* a long time ago, not branches that have been *created* (i.e., spliced off of some parent) a long time ago. I believe this is what the OP actually wanted (as opposed to the title he chose for the question), as this would lead to good candidates for deletion.</em></p>
  
  <p>You have to recall that a branch in git is nothing "physical". It is, by definition, and literally, <em>only</em> a simple text file in <code>.git/refs</code> which only has its file name (which is the branch name) and the hash of the tip/head commit. It has no date information or <em>anything</em> else.</p>
  
  <p>So <code>git branch</code> will not help you here. </p>
  
  <p>The object type that has dates associated with it are commits, in git. So you have to list commits. This is done with <code>git log</code>. </p>
  
  <p>So a working command would be:</p>
  
  <pre><code>git log --remotes --before 2018-01-01 --no-walk --decorate
  </code></pre>
  
  <p>You can read up the details on <a href="https://www.git-scm.com/docs/git-log" rel="noreferrer">https://www.git-scm.com/docs/git-log</a> , but in short, it means </p>
  
  <ul>
  <li><code>--remotes</code>: start with any and all remote branches (substitute <code>--branches</code> for local branches)</li>
  <li><code>--before ...</code>: only list commits older than the date given</li>
  <li><code>--no-walk</code>: only list the very first commit for each branch, don't walk back the history</li>
  <li><code>--decorate</code>: display all tag and branch names associated, just in case</li>
  </ul>
  
  <p>This will give you all branch heads that are older than your given date.</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-02-11T13:37:06.173Z
Answers: The branches older than X are shown (+1), but also some details. Would it also be possible to just return the branch names, like the output of `git branch`?
Answers: 030
Answers: CC BY-SA 3.0
Answers: 2018-02-11T16:13:25.303Z
Answers: See this SO answer https://stackoverflow.com/questions/10325599/delete-all-branches-that-are-more-than-x-days-weeks-old
Answers: Vorsprung
Answers: CC BY-SA 3.0
Answers: 2018-02-11T19:24:11.040Z
Answers: Sure, @030, the `--format` option can be used to only output the ref (branch) names, if needed. Vorsprung also linked a duplicate question which uses little bash scripts to iterate over the branches and deletes stuff.
Answers: AnoE
Answers: CC BY-SA 4.0
Answers: 2023-04-20T12:00:27.550Z
Answers: this command show only tracked remote branch not all remote.
Answers: OfusJK
Answers: CC BY-SA 3.0
Answers: 2018-02-09T23:18:02.713Z
Answers: 2018-02-09T23:30:36.367Z
Answers: 2018-02-09T23:30:36.367Z
Answers: AnoE
Body: <p>Git is used at work. The number of branches is growing and growing. The aim is to remove branches that are older than X weeks.</p>
  
  <p><strong>Attempt 1</strong></p>
  
  <p>Running <code>git branch -h</code> will probably indicate what to run to check when a branch has been created.</p>
  
  <pre><code>user@localhost $ git branch -h
  usage: git branch [&lt;options&gt;] [-r | -a] [--merged | --no-merged]
     or: git branch [&lt;options&gt;] [-l] [-f] &lt;branch-name&gt; [&lt;start-point&gt;]
     or: git branch [&lt;options&gt;] [-r] (-d | -D) &lt;branch-name&gt;...
     or: git branch [&lt;options&gt;] (-m | -M) [&lt;old-branch&gt;] &lt;new-branch&gt;
     or: git branch [&lt;options&gt;] [-r | -a] [--points-at]
  
  Generic options
      -v, --verbose         show hash and subject, give twice for upstream branch
      -q, --quiet           suppress informational messages
      -t, --track           set up tracking mode (see git-pull(1))
      --set-upstream        change upstream info
      -u, --set-upstream-to &lt;upstream&gt;
                            change the upstream info
      --unset-upstream      Unset the upstream info
      --color[=&lt;when&gt;]      use colored output
      -r, --remotes         act on remote-tracking branches
      --contains &lt;commit&gt;   print only branches that contain the commit
      --abbrev[=&lt;n&gt;]        use &lt;n&gt; digits to display SHA-1s
  
  Specific git-branch actions:
      -a, --all             list both remote-tracking and local branches
      -d, --delete          delete fully merged branch
      -D                    delete branch (even if not merged)
      -m, --move            move/rename a branch and its reflog
      -M                    move/rename a branch, even if target exists
      --list                list branch names
      -l, --create-reflog   create the branch's reflog
      --edit-description    edit the description for the branch
      -f, --force           force creation, move/rename, deletion
      --merged &lt;commit&gt;     print only branches that are merged
      --no-merged &lt;commit&gt;  print only branches that are not merged
      --column[=&lt;style&gt;]    list branches in columns
      --sort &lt;key&gt;          field name to sort on
      --points-at &lt;object&gt;  print only branches of the object
  </code></pre>
  
  <p><strong>Attempt 2</strong></p>
  
  <p>This post <a href="https://stackoverflow.com/questions/3184555/cleaning-up-old-remote-git-branches">https://stackoverflow.com/questions/3184555/cleaning-up-old-remote-git-branches</a> was found, but this is not an option as it removes branches without checking the age.</p>
  
Comments: CC BY-SA 3.0
Comments: 2018-02-09T21:59:33.677Z
Comments: Git doesn't store creation date of branches afaik.  Is it ok to remove branches that haven't been *committed to* recently?
Comments: Xiong Chiamiov
Comments: CC BY-SA 3.0
Comments: 2018-02-09T22:07:40.220Z
Comments: @XiongChiamiov What is your definition of `recently`?
Comments: 030
Comments: CC BY-SA 3.0
Comments: 2018-02-12T20:18:12.640Z
Comments: Whatever it is you want.  The important part of that sentence is "committed to" versus "created".
Comments: Xiong Chiamiov
Tags: <git>
Title: What git command could be used to check when a remote branch was created?
UserDisplayName: 030
ThreadText: # What git command could be used to check when a remote branch was created?
  
  (Asked by: username_0 on 2018-02-09)
  
  Git is used at work. The number of branches is growing and growing. The aim is to remove branches that are older than X weeks.
  
  **Attempt 1**
  
  Running `git branch -h` will probably indicate what to run to check when a branch has been created.
  
  ```
  user@localhost $ git branch -h
  usage: git branch [<options>] [-r | -a] [--merged | --no-merged]
     or: git branch [<options>] [-l] [-f] <branch-name> [<start-point>]
     or: git branch [<options>] [-r] (-d | -D) <branch-name>...
     or: git branch [<options>] (-m | -M) [<old-branch>] <new-branch>
     or: git branch [<options>] [-r | -a] [--points-at]
  
  Generic options
      -v, --verbose         show hash and subject, give twice for upstream branch
      -q, --quiet           suppress informational messages
      -t, --track           set up tracking mode (see git-pull(1))
      --set-upstream        change upstream info
      -u, --set-upstream-to <upstream>
                            change the upstream info
      --unset-upstream      Unset the upstream info
      --color[=<when>]      use colored output
      -r, --remotes         act on remote-tracking branches
      --contains <commit>   print only branches that contain the commit
      --abbrev[=<n>]        use <n> digits to display SHA-1s
  
  Specific git-branch actions:
      -a, --all             list both remote-tracking and local branches
      -d, --delete          delete fully merged branch
      -D                    delete branch (even if not merged)
      -m, --move            move/rename a branch and its reflog
      -M                    move/rename a branch, even if target exists
      --list                list branch names
      -l, --create-reflog   create the branch's reflog
      --edit-description    edit the description for the branch
      -f, --force           force creation, move/rename, deletion
      --merged <commit>     print only branches that are merged
      --no-merged <commit>  print only branches that are not merged
      --column[=<style>]    list branches in columns
      --sort <key>          field name to sort on
      --points-at <object>  print only branches of the object
  
  ```
  
  **Attempt 2**
  
  This post <https://stackoverflow.com/questions/3184555/cleaning-up-old-remote-git-branches> was found, but this is not an option as it removes branches without checking the age.
  
  **Tags:** git
  
  > **Comments:**
  > **username_1**: Git doesn't store creation date of branches afaik.  Is it ok to remove branches that haven't been *committed to* recently?  
  > **username_0**: @username_1 What is your definition of `recently`?  
  > **username_1**: Whatever it is you want.  The important part of that sentence is "committed to" versus "created".  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-02-09. Score: 7 | Accepted answer
  
  *Note: this answer shows how to find branches that have been \*updated\* a long time ago, not branches that have been \*created\* (i.e., spliced off of some parent) a long time ago. I believe this is what the OP actually wanted (as opposed to the title he chose for the question), as this would lead to good candidates for deletion.*
  
  You have to recall that a branch in git is nothing "physical". It is, by definition, and literally, *only* a simple text file in `.git/refs` which only has its file name (which is the branch name) and the hash of the tip/head commit. It has no date information or *anything* else.
  
  So `git branch` will not help you here.
  
  The object type that has dates associated with it are commits, in git. So you have to list commits. This is done with `git log`.
  
  So a working command would be:
  
  ```
  git log --remotes --before 2018-01-01 --no-walk --decorate
  
  ```
  
  You can read up the details on <https://www.git-scm.com/docs/git-log> , but in short, it means
  
  * `--remotes`: start with any and all remote branches (substitute `--branches` for local branches)
  * `--before ...`: only list commits older than the date given
  * `--no-walk`: only list the very first commit for each branch, don't walk back the history
  * `--decorate`: display all tag and branch names associated, just in case
  
  This will give you all branch heads that are older than your given date.
  
  > **Comments:**
  > **username_0**: The branches older than X are shown (+1), but also some details. Would it also be possible to just return the branch names, like the output of `git branch`?  
  > **username_3**: See this SO answer https://stackoverflow.com/questions/10325599/delete-all-branches-that-are-more-than-x-days-weeks-old  
  > **username_2**: Sure, @username_0, the `--format` option can be used to only output the ref (branch) names, if needed. username_3 also linked a duplicate question which uses little bash scripts to iterate over the branches and deletes stuff.  
  > **username_4**: this command show only tracked remote branch not all remote.  
  
  ---
  
  