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?
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.
Hi @Tim Dery ,
Have you tried just using git commands in the script section?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.