Ali SAID OMAR
Ali SAID OMAR

Reputation: 6792

git get the branch where the last commit have been done

I'm looking the way to the get the branch where the last commit have be done, now i'm doing something like

last_co_branch=$(git branch --sort=-committerdate| head -1| grep -o -e "develop" -e "master")

if [[ "$last_co_branch" == "master" ]]; then

  # stuff ... 
fi 

if [[ "$last_co_branch" == "develop" ]]; then

  # stuff ... 
fi 

but it's looking weird.

Upvotes: 1

Views: 70

Answers (1)

sagunms
sagunms

Reputation: 8515

You could do something like this:

last_co_branch=$(git for-each-ref --count=1 --sort=-committerdate refs/heads/ --format='%(refname:short)')
if [[ "$last_co_branch" == "master" ]]; then
  # stuff ... 
fi 
if [[ "$last_co_branch" == "develop" ]]; then
  # stuff ... 
fi 

Upvotes: 1

Related Questions