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

fatal: You are not currently on a branch. To push the history leading to the current (detached HEAD) #719

Open
1Mark opened this issue Mar 12, 2022 · 7 comments

Comments

@1Mark
Copy link

1Mark commented Mar 12, 2022

I've already read #124

I'm trying to push a commit during release but no success

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

python-publish.yml looks like

name: Upload Python Package

on:
  release:
    types: [published,  workflow_dispatch]

jobs:
  deploy:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      with:
        ref: ${{ github.ref }}
        fetch-depth: 0 # probably don't need this 
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Bump package version to ${{ github.ref_name }}
      run: |
        git config user.name "GitHub Actions Bot"
        git config user.email "<>"
        pip install bump2version==1.0.1
        # Here we don't use ${{ github.ref_name }} since github action variables can't do sed/cut/slicing
        # Remove leading 'v' from the tag name
        bump2version --new-version ${GITHUB_REF_NAME#v} minor
        # must supply either patch minor or major see https://github.com/c4urself/bump2version/issues/244
        # but it's an ignored argument argument
        git show
        git push
@Fleshgrinder
Copy link

Seems like things changed in v3 and this is what I have in the log:

  /usr/bin/git checkout --progress --force refs/remotes/pull/3/merge
  Note: switching to 'refs/remotes/pull/3/merge'.
  
  You are in 'detached HEAD' state. You can look around, make experimental
  changes and commit them, and you can discard any commits you make in this
  state without impacting any branches by switching back to a branch.
  
  If you want to create a new branch to retain commits you create, you may
  do so (now or later) by using -c with the switch command. Example:
  
    git switch -c <new-branch-name>
  
  Or undo this operation with:
  
    git switch -
  
  Turn off this advice by setting config variable advice.detachedHead to false
  
  HEAD is now at 4de7325 Merge 90e2ccdb6fca8684e7b90e1f2f0e449752846580 into d8b663327122c864bd9141074ecd5901252d7869

This also means that the https://github.com/actions/checkout#Push-a-commit-using-the-built-in-token section is not correct anymore.

@Fleshgrinder
Copy link

Fleshgrinder commented Apr 6, 2022

I was able to get it to work with v3:

    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        ref: ${{ github.event.pull_request.head.ref }}
    - run: |
        date >generated.txt
        git config user.name github-actions
        git config user.email [email protected]
        git add --all .
        git commit --message test
        git push

If the commit should trigger workflows things get more complicated and a personal access token (PAT) is required:

    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        ref: ${{ github.event.pull_request.head.ref }}
        token: ${{ secrets.pat }}
    - run: |
        date >generated.txt
        user=$(gh api /user)
        user_name=$(jq -r '.login' <<<"$user")
        user_email=$(jq -r ".email | \"[email protected]\"" <<<"$user")
        git config user.name "$user_name"
        git config user.email "$user_email"
        git add --all .
        git commit --message test
        git push
      shell: bash

Note that the fallback email address might not be correct if the user created the email address after July 18, 2017.1

Note further that it is not possible to cancel the workflow, the only way to stop the current workflow and let it run again is via exit 1.2

Footnotes

  1. https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-user-account/managing-email-preferences/setting-your-commit-email-address#about-commit-email-addresses

  2. https://github.com/actions/runner/issues/662

@Shelton2020
Copy link

Bring it home

@1Mark
Copy link
Author

1Mark commented Apr 6, 2022

Seems like things changed in v3 and this is what I have in the log:

  /usr/bin/git checkout --progress --force refs/remotes/pull/3/merge
  Note: switching to 'refs/remotes/pull/3/merge'.
  
  You are in 'detached HEAD' state. You can look around, make experimental
  changes and commit them, and you can discard any commits you make in this
  state without impacting any branches by switching back to a branch.
  
  If you want to create a new branch to retain commits you create, you may
  do so (now or later) by using -c with the switch command. Example:
  
    git switch -c <new-branch-name>
  
  Or undo this operation with:
  
    git switch -
  
  Turn off this advice by setting config variable advice.detachedHead to false
  
  HEAD is now at 4de7325 Merge 90e2ccdb6fca8684e7b90e1f2f0e449752846580 into d8b663327122c864bd9141074ecd5901252d7869

This also means that the https://github.com/actions/checkout#Push-a-commit-using-the-built-in-token section is not correct anymore.

Thanks for your assistance but im trying to get it to push when creating a release

ref: ${{ github.event.pull_request.head.ref }} won't work for me.

@Fleshgrinder
Copy link

Fleshgrinder commented Apr 6, 2022

Sorry that I missed it, you have:

on:
  release:
    types: [published,  workflow_dispatch]

This actually should be as follows to work as expected since workflow_dispatch is not a valid release type (see):

on:
  release:
    types: [published]
  workflow_dispatch:

In your case it is not entirely clear where you want to commit and push to, since a release can refer to any commit within the entire history of the repository. I see multiple ways on how to solve this, but it would be important to know what it is you exactly want to achieve.

@1Mark
Copy link
Author

1Mark commented Apr 6, 2022

So I've tried to find a standardised way to do this but I cannot.

Here is a vanilla example of what I'm trying to achieve

https://github.com/spec-first/connexion/blob/main/.github/workflows/release.yml#L22

So we create a new release which triggers a new commit with newest version (updating the src code) and then tags it with that version and pushes both.

@ondrados
Copy link

I probably have similar problem when using awsebcli to deploy my application to AWS Elastic Beanstalk. It uses current git branch to decide which environment should be deployed (dev branch -> dev environment, master branch -> production environment, etc.)

After action/checkout@v2 (I have tried older v2.4.0 and even v3) i have action where i simply install cli and run eb deploy. Now i am getting this message

WARNING: Git is in a detached head state. Using branch "default".

And since branch default is not set, because i need to only deploy specific branches to specific environments, nothing is deployed.

Last successful action ran 5 days ago.

ValarDragon added a commit to osmosis-labs/osmosis that referenced this issue Aug 8, 2023
ValarDragon added a commit to osmosis-labs/osmosis that referenced this issue Aug 8, 2023
* Try committing result

* fix indent

* fix cmd

* try-token

* Tryfix

* try again

* Try again

* try docs suggested method

* try simpler thing

* ah wrong perms at top

* try agian

* Try actions/checkout#317

* try actions/checkout#719

* Generated protofile changes

* Try again

* Generated protofile changes

* use proper paths filtering

* Make it do make proto-all

* Rename workflow, add go.sum to diff list

---------

Co-authored-by: github-actions <[email protected]>
Co-authored-by: devbot-wizard <[email protected]>
p0mvn pushed a commit to osmosis-labs/osmosis that referenced this issue Aug 29, 2023
* Try committing result

* fix indent

* fix cmd

* try-token

* Tryfix

* try again

* Try again

* try docs suggested method

* try simpler thing

* ah wrong perms at top

* try agian

* Try actions/checkout#317

* try actions/checkout#719

* Generated protofile changes

* Try again

* Generated protofile changes

* use proper paths filtering

* Make it do make proto-all

* Rename workflow, add go.sum to diff list

---------

Co-authored-by: github-actions <[email protected]>
Co-authored-by: devbot-wizard <[email protected]>
edmundmiller added a commit to nf-core/modules that referenced this issue Aug 8, 2024
edmundmiller added a commit to nf-core/modules that referenced this issue Aug 8, 2024
edmundmiller added a commit to nf-core/modules that referenced this issue Aug 8, 2024
edmundmiller added a commit to nf-core/modules that referenced this issue Aug 9, 2024
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

4 participants