{"record":{"id":"c8939f6c4fc30353","repo":"linera-io/linera-protocol","slug":"head-is-not-on-a-branch-it-may-be-detached","errorCode":null,"errorMessage":"HEAD is not on a branch - it may be detached","messagePattern":"HEAD is not on a branch - it may be detached","errorType":"exception","errorClass":"anyhow","httpStatus":null,"severity":"error","filePath":"linera-summary/src/github.rs","lineNumber":97,"sourceCode":"    }\n\n    /// Returns the repository the PR belongs to.\n    pub fn repository(&self) -> &GithubRepository {\n        &self.repository\n    }\n\n    fn get_local_git_info() -> Result<(String, String, String)> {\n        let repo = git2::Repository::open_from_env().context(\"Failed to open git repository\")?;\n\n        let head = repo.head()?;\n        let commit_hash = head.peel_to_commit()?.id().to_string();\n\n        let branch_name = if head.is_branch() {\n            head.shorthand()\n                .ok_or_else(|| anyhow!(\"Failed to get current branch name\"))?\n                .to_string()\n        } else {\n            anyhow::bail!(\"HEAD is not on a branch - it may be detached\");\n        };\n\n        // This local mode is only used for testing, so we're just hardcoding `main` as the base branch for now.\n        Ok((commit_hash, branch_name, \"main\".to_string()))\n    }\n\n    fn from_env(is_local: bool, pr_number: Option<u64>) -> Result<Self> {\n        let env_pr_commit_hash = env::var(\"GITHUB_PR_COMMIT_HASH\");\n        let env_pr_branch = env::var(\"GITHUB_PR_BRANCH\");\n        let env_base_branch = env::var(\"GITHUB_BASE_BRANCH\");\n        let env_pr_number = env::var(\"GITHUB_PR_NUMBER\");\n\n        let (pr_commit_hash, pr_branch, base_branch, pr_number) = if is_local {\n            let (commit_hash, branch_name, base) = Self::get_local_git_info()?;\n            (\n                commit_hash,\n                branch_name,\n                base,","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-summary/src/github.rs#L79-L115","documentation":"Raised by `GithubContext::get_local_git_info` (linera-summary github.rs) when the tool runs in local mode and the current git repository's HEAD does not point at a branch (git2's `head().is_branch()` is false). A detached HEAD (or any non-branch symbolic ref) has no branch name to report, so the summary context cannot be built. Local mode is a testing path that reads the branch name from the working copy.","triggerScenarios":"Running linera-summary locally with `is_local = true` while HEAD is detached — e.g. after `git checkout <sha>`, an interrupted `git rebase`, or a CI checkout (actions/checkout checks out the PR commit by default, which is detached).","commonSituations":"Running the PR-summary tool on a CI runner where actions/checkout left HEAD detached; locally testing a specific commit without creating a branch; mid-rebase working copies.","solutions":["Attach HEAD to a branch before running: `git checkout -b <branch>` (or `git checkout <existing-branch>`)","In GitHub Actions, configure `actions/checkout` with `ref: <branch>` so HEAD is on a branch","Run in non-local mode instead by setting GITHUB_PR_COMMIT_HASH, GITHUB_PR_BRANCH, GITHUB_BASE_BRANCH and GITHUB_PR_NUMBER"],"exampleFix":"# before\ngit checkout 1a2b3c4   # detached HEAD\nlinera-summary ...           # -> bail: HEAD is not on a branch\n\n# after\ngit checkout -b pr-analysis 1a2b3c4\nlinera-summary ...","handlingStrategy":"validation","validationCode":"# Check HEAD is on a branch before running linera-summary in local mode\nif ! git symbolic-ref -q HEAD > /dev/null; then\n  echo \"detached HEAD: create a branch first (git checkout -b <name>)\" >&2\n  exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In CI, set `ref:` on actions/checkout so HEAD lands on a branch","Never run the local-mode summary right after `git checkout <sha>` — create a branch first","Prefer the env-var mode (GITHUB_PR_COMMIT_HASH / GITHUB_PR_BRANCH / GITHUB_BASE_BRANCH / GITHUB_PR_NUMBER) in automation"],"tags":["git","ci","github","tooling"],"backgroundTag":"git-detached-head","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}