question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

I’ve already read https://github.com/actions/checkout/issues/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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

1reaction
Shelton2020commented, Apr 6, 2022

Bring it home

1reaction
Fleshgrindercommented, 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 github-actions@github.com
        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 | \"$user_name@users.noreply.github.com\"" <<<"$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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Git push master fatal: You are not currently on a branch
But when I try to push to master I get. fatal: You are not currently on a branch. To push the history leading...
Read more >
Correcting detached head problems with Git - Acquia Docs
This detached head state occurs when a specific commit is checked out instead of a branch. You cannot commit to a commit—only to...
Read more >
Recovering from the Git detached HEAD state - CircleCI
Not at all. It just means you are not currently attached to any branch, and as a result, your HEAD is detached. If...
Read more >
git submodules - faq.sa
my_submodule$ git push fatal: You are not currently on a branch. To push the history leading to the current (detached HEAD) state now,...
Read more >
What's a "detached HEAD" in Git? | Learn Version Control with ...
The HEAD pointer in Git determines your current working revision (and thereby the files that are placed in your project's working directory). Normally,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found