Skip to content

Smarter or better documentation for the base git branch name configuration #2611

@theofidry

Description

@theofidry

To get the default base branch name we execute:

git symbolic-ref refs/remotes/origin/HEAD'

This definitely fits most cases and the user can always specify their own so this issue is more of a QoL for edge cases.

The issue:

  • A different remote than origin may be configured (e.g. upstream, which is commonly used in forks).
  • Multiple remotes may be configured.

The branch the user is one may have a default branch it tracks hence we could figure that out:

git rev-parse --abbrev-ref --symbolic-full-name @{upstream}

However, especially in the CI, it is in a detached state hence this won't work. This can be manually configured:

GitHub Actions:

- uses: actions/checkout@v4
  with:
    ref: ${{ github.head_ref }}  # Check out the actual branch, not detached HEAD

GitLab CI:

variables:
  GIT_STRATEGY: clone
  GIT_CHECKOUT: "true"

And then:

git checkout -B $CI_COMMIT_REF_NAME
git branch --set-upstream-to=origin/$CI_COMMIT_REF_NAME

To investigate if there are any actionables here to improve the user experience. A non-exhaustive list of points to explore:

-better defaults

  • more fallback
  • nicer failure message
  • documentation.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions