Detect current branch properly