Reputation: 41
I am pretty new in Bash. On git, I have branches named like following (YYcwXX):
I want to iterate among them and store the one which has the latest current week number - e.g 21cw24 in a variable.
Upvotes: 0
Views: 78
Reputation: 311338
I'd use git branch
to list the relevant branches, sort them, and use tail
to take the last. Then, I'd just trim away whitespaces and store in a variable:
export MY_BRANCH=`git branch | grep 'version/' | sort | tail -1 | tr -d ' '`
Upvotes: 3