Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to git checkout to specific branch in git submodule #1815

Open
elmarsan opened this issue Jul 9, 2024 · 1 comment
Open

Unable to git checkout to specific branch in git submodule #1815

elmarsan opened this issue Jul 9, 2024 · 1 comment

Comments

@elmarsan
Copy link

elmarsan commented Jul 9, 2024

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 }}
@eXpl0it3r
Copy link

Why do you need a specific branch in the submodule? Why is a detached head of a commit not sufficient?

Are you then later committing changes within the submodule?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants