NoStupidQuestions
NoStupidQuestions

Reputation: 23

Checkout most recent commit on any branch

I would like to checkout the latest commit on an active repository of any branch. That's the first commit when you sort your Bitbucket repo in the "Network" section.

My use case is a tool which uses code from latest changes in multiple submodules to analyze if those changes have led to a better evaluation metric. I'm doing it though a Jenkinsfile

I tried:

git checkout HEAD

but that only checks out the latest commit in the current branch.

Upvotes: 0

Views: 111

Answers (2)

jthill
jthill

Reputation: 60235

git checkout :/.

The :/ syntax is "the most recent commit whose message contains a match for the expression", and . is "any character".

Upvotes: 0

Jim
Jim

Reputation: 327

git rev-list -n1 origin --branches=* | xargs git checkout

Upvotes: 1

Related Questions