How can i get a list of branches which are only final branches (which are not parents of any other commits) - other words branches which are tips of commit tree (final nodes).
I expected some option like --final or --tips in git branch
command but there only --merged, --no-merged and --contains options.
Use git branch --sort=-committerdate to display a list of all local branches and sort them based on the date of their last commit. Use arrow keys to navigate, press Q to exit.
If you need to get latest commit on a branch through the REST api, try the "/commits" call with the "until" parameter set to the branch you are interested in, and limit=1 to get the single tip commit from the branch.
Git keeps track of updates to the tip of branches using a mechanism called reference logs, or "reflogs." Many Git commands accept a parameter for specifying a reference or "ref", which is a pointer to a commit. Common examples include: git checkout. git reset.
To get a list of all branches from the remote, run this command: git pull.
There are some useful answers already but not giving what is asked for: a list or branches (to me that means branch names, not commit IDs).
{
echo "** Below is list of tip branches a.k.a. final nodes."
echo "** These aren't reachable from any other branches."
echo "** Removing them is potentially DANGEROUS: it would make some commit unreachable."
TIPS=$( git rev-list --branches --children | grep -v ' ' | sort )
{ while read branchname commitid message
do grep $commitid < <(echo $TIPS) -q && echo $branchname
done
} < <(git branch -v --no-abbrev | sed 's/\*//' )
echo "** end of list"
}
Result looks like this:
** Below is list of tip branches a.k.a. final nodes.
** These aren't reachable from any other branches.
** Removing them is potentially DANGEROUS: it would make some commit unreachable.
feature-workingonit
dev
** end of list
When tidying things up, you may want to see the non-tip branches. Here's a way to get a list of them. The only change is &&
becoming ||
.
{
echo "** Below is list of non-tip branches a.k.a. inner nodes."
echo "** These are reachable from other branches."
echo "** If you remove them, all commits would stay reachable, but be careful anyway."
TIPS=$( git rev-list --branches --children | grep -v ' ' | sort )
{ while read branchname commitid message
do grep $commitid < <(echo $TIPS) -q || echo $branchname
done
} < <(git branch -v --no-abbrev | sed 's/\*//' )
echo "** end of list"
}
Result looks like this:
** Below is list of non-tip branches a.k.a. inner nodes.
** These are reachable from other branches.
** If you remove them, all commits would stay reachable, but be careful anyway.
feature-alreadymerged
master
** end of list
You can decorate as you wish, for example by changing:
echo $branchname
into
echo -e "$branchname\t$commitid\t$message"
Result then looks like this:
** Below is list of non-tip branches a.k.a. inner nodes.
** These are reachable from other branches.
** If you remove them, all commits would stay reachable, but be careful anyway.
feature-alreadymerged 426ac5186841876163970afdcc5774d46641abc4 Cool feature foo, ref task #1234
master 39148238924687239872eea425c0e837fafdcfd9 Some commit
** end of list
You can then review those branches in your favorite tool to see if it makes sense to remove them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With