Skip to main content

get_current_branch

Function get_current_branch 

Source
pub fn get_current_branch(path: &Path) -> Option<String>
Expand description

Get the current git branch name for the repository containing path.

Reads the HEAD file directly, handling both normal repos and worktrees (where .git is a file with gitdir: prefix).

Returns Some(branch_name) when HEAD points to a branch reference (e.g., refs/heads/main"main"). Returns Some(commit_hash) when HEAD is detached. Returns None when HEAD cannot be read.