Skip to content

allow Repository.set_head on unborn branches? #1374

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

Closed
calestyo opened this issue May 12, 2025 · 1 comment
Closed

allow Repository.set_head on unborn branches? #1374

calestyo opened this issue May 12, 2025 · 1 comment

Comments

@calestyo
Copy link

calestyo commented May 12, 2025

Hey.

I work on an empty repo that may have been created with git init (and thus it's .git/HEAD contains ref: refs/heads/master.

Now I want to write some commit but to a branch other than the default branch master.

I had kinda hoped that I could simply use repo.set_head("refs/heads/mybranch") and when I then repo.create_commit("HEAD",... it would use that.

But set_head already fails when the branch doesn't exist yet.

From what I could see from the sources, set_head uses libgit2’s git_repository_set_head() and that indeed seems to be documented as being usable with unborn branches:

If the provided reference points to a branch, the HEAD will point to that branch, staying attached, or become attached if it isn't yet. If the branch doesn't exist yet, no error will be return. The HEAD will then be attached to an unborn branch.

Any way to get that with pygit2?

Thanks,
Chris.

@calestyo
Copy link
Author

Strange. I've tested the same thing again, and now it works.
Not sure what I did wrong in the first place.

Thus closing.

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

No branches or pull requests

1 participant