Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A small script to find stale branches
#!/bin/bash
# This is a very naive script, it doesn't do grouping and returns all branches
# I only really care about branches that have not seen commits in two months
#
# I am hoping to find some time to write a tool that can output these reports for me
# In the meantime, I am using this
echo "Merged branches"
for branch in `git branch -r --merged | grep -v HEAD`;do echo -e `git log --no-merges -n 1 --format="%ci, %cr, %an, %ae, " $branch | head -n 1` \\t$branch; done | sort -r
echo ""
echo "Not merged branches"
for branch in `git branch -r --no-merged | grep -v HEAD`;do echo -e `git log --no-merges -n 1 --format="%ci, %cr, %an, %ae, " $branch | head -n 1` \\t$branch; done | sort -r
@trntsmn

This comment has been minimized.

Copy link

@trntsmn trntsmn commented May 21, 2019

Quickly hacked together a powershell version in case it helps anyone
`#! /usr/bin/pwsh

echo ""
echo "Not merged branches"
$branches = git branch -r --no-merged | grep -v HEAD
$output = @()
foreach( $branch in $branches ) {
$branch = $branch.Trim()
$output += git log -n 1 --format="%ci, %cr, %an, %ae, $branch" --no-merges --first-parent $branch | Sort-Object
}
echo $output`

@naidubrahma

This comment has been minimized.

Copy link

@naidubrahma naidubrahma commented Jun 19, 2019

Could you please suggest me how to list all the branches under enitirr gitlab

@renatoathaydes

This comment has been minimized.

Copy link

@renatoathaydes renatoathaydes commented Jul 3, 2019

It's a good idea to change the column separators because the dates in the output contain ,, so another column separator like | is more appropriate to avoid confusion.
Just change --format="%ci, %cr, %an, %ae, " to --format="%ci | %cr | %an | %ae | ".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment