actions / actions/checkout

Unable to git checkout to specific branch in git submodule

Open
#1,815 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
8.9k
Forks
2.8k
PR merge metrics
No merged PRs in 30d

Description

I am trying to achieve something that I am not sure is possible. I haven't been able to find any similar cases to mine, which is why I am creating this issue. The goal is to see if anyone has encountered this before and knows how to resolve it. I wouldn't say it's a problem per se, just a request for help.

Context

My repository has two git submodules and looks like this:

/src
/submodule_1
/submodule_2

My use case is a bit special because the repository is closely related to one of the git submodules. From now on, I will only mention the "git submodule" and ignore the other one since none of this concerns the other.

Basically, my workflow is triggered by pull requests, and I need to be able to clone the submodule and checkout to a branch with the same name (if a branch with the same name does not exist, master should be used).

This is how I try to checkout in the submodule:

cd submodule_folder
git fetch --all
git merge origin/master
# Try to checkout to branch with same name or master if it does not exist
git checkout -b "origin/$GITHUB_HEAD_REF" 2>&1 | grep -wi 'fatal' && git checkout master
git pull

Then after that, I need to execute some script from that submodule. The problem is I can't checkout to the branch I want (The branch exists in the origin of the git submodule repository, double-checked).

Action configuration:

# ....
# ....
steps:
  - uses: actions/checkout@v3
    with:
       submodules: recursive
       token: ${{ secrets.ACCESS_TOKEN }}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the actions/checkout@v3 step and the submodule checkout commands shown in the issue. Check how recursive submodules are initialized and whether the action exposes an entry point for selecting a submodule branch. Done means a reproducible workflow checks out the matching submodule branch and falls back to master when it is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, github-actions, shell, typescript
Domain
ci-cd, devops
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.