Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an GIT_HEAD_IS_DEFAULT_BRANCH variable. #33

Open
jmalloc opened this issue Jan 31, 2020 · 0 comments
Open

Add an GIT_HEAD_IS_DEFAULT_BRANCH variable. #33

jmalloc opened this issue Jan 31, 2020 · 0 comments

Comments

@jmalloc
Copy link
Contributor

jmalloc commented Jan 31, 2020

The default branch can be obtained reliably by querying the origin server using:

git remote show origin | grep "  HEAD branch:" | cut -c16-

We could check locally first by querying the HEAD of origin (not the HEAD of any particular branch, but the origin remote itself):

git symbolic-ref refs/remotes/origin/HEAD

However, this can be unavailable, or get out of sync if the default branch is changed after the clone is made. That's not a big concern for CI, but it is for long-lived clones on development workstations.

git remote set-head origin --auto

The command above can be used to sync the ref locally, but that obviously has to contact the server anyway, so is no faster than the git remote show approach.

As an aside, it seems that grit does not populate the remote head locally when cloning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant