Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Check out one additional branch in bitbucket pipeline

Tim Dery
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 29, 2024

In a pipeline step, I want to check out one more branch than the branch the pipeline is running on (the main branch).

I found the "clone: depth: full" option, which works.

However, that grabs all the branches in the repo, which takes additional time getting things that I don't need, especially if there's a lot of branches.

Is there a way to check out exactly one additional branch in a pipeline?

 

2 answers

1 accepted

0 votes
Answer accepted
Tim Dery
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 30, 2024

I answered my own question with help from https://community.atlassian.com/t5/Bitbucket-questions/Bitbucket-pipelines-Checkout-a-different-branch-than-master/qaq-p/2220686

You can't just check out another branch from a pipeline. A `git branch -a` shows that the default pipeline's git only knows about the branch it's running on:

git branch -a
* my-branch
remotes/origin/my-branch

If you try to check out any other branch, it errors out because git doesn't know about any other branch.

If you run

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

Then

git fetch

git will see all of the branches and you can check them out etc

For my specific case, this isn't what I want, as it's pulling info on all the branches, which is effectively the same as a "clone depth:full" - it takes time to get all that info depending on the number of branches.

However, if I do

git config remote.origin.fetch "+refs/heads/main:refs/remotes/origin/main"

and

git fetch

then git can see the branch it's running on and branch main:

git branch -a
* my-branch
remotes/origin/main
remotes/origin/my-branch

which I'm then able to use in my pipeline.

0 votes
Saxea _Flowie_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 29, 2024

Hi @Tim Dery ,

Have you tried just using git commands in the script section?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events