You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gh release create question and general feedback #2133
I really love the whole cli. Thanks a lot for making it open source as well. As a Gopher, it's really great to see this code as it's awesome! So, thanks!
What was confusing or gave you pause?
Previously, to make a release, I would commit my code locally and push to Github, add a tag to my commit (say v0.2.0) and then run git push origin v0.2.0 to create my release on Github.
With the gh cli, I don't even need to add a local tag, I just type gh release create v0.2.0 and it works, but my local git repository is not given the tag, so they are a bit disjointed. I can go and add the tag after the fact, but I'm wondering if there's a way for it to release given the local tag? Git is not my specialty, so I'm not sure if this even makes sense, but wondering how to couple my local git tag to a Github release a bit more tightly.
Previously, to make a release, I would commit my code locally and push to Github, add a tag to my commit (say v0.2.0) and then run git push origin v0.2.0 to create my release on Github.
This does push a git tag to your GitHub repo, which shows up among "releases" for your repository, but it's not a full GitHub Release in a sense that you can edit the release notes in Markdown format or upload your own assets to it. The gh release create command helps with creating a proper Release.
With the gh cli, I don't even need to add a local tag, I just type gh release create v0.2.0 and it works, but my local git repository is not given the tag, so they are a bit disjointed.
I see! In case that you haven't created the v0.2.0 git tag yourself, the fact that you've created a v0.2.0 Release on GitHub will automatically create the underlying v0.2.0 git tag in your remote repository. The new tag will be created off the latest state of your default branch (e.g. main), but you can change that by passing the --target parameter to release create with a specific commit SHA or a branch name where you want the new tag to point to.
Finally, to fetch the new git tag locally, you can do git fetch origin --tags.
We can definitely make sure to document all this better in release create, but other than just clearer documentation, is there something else that is confusing here or that you imagine should work differently?
For example, would you expect us to automatically pull the newly created git tag locally after you've done release create?
Would it be possible to add the tag locally and then use the tag for a target? e.g. gh release create --target-tag v0.2.0 or just recognize a semver pattern to enable gh release create --target v0.2.0
Or does that not make sense? Pulling the tag locally after could work, but my typical flow, because of Go Modules, is to tag in my IDE and then push releases. I'm probably an outlier, I'm no Git wiz and can change my process!
@gilcrest It's absolutely possible to first create a tag locally and then create a release for it. The --target argument accepts commit SHAs, branch names, or tag names.
Actually, I think that --target v0.2.0 in the last command isn't needed, because the v0.2.0 Release will automatically get tied to the v0.2.0 git tag if one already exists. The --target argument only has effect, I think, when the git tag doesn't yet exist in the repository.
Does this answer your questions? Is there something that you imagine gh should do differently around release create? I'm hoping to define something actionable, if a change is needed, from this thread. 🙇
--target branch Target branch or commit SHA (default: main branch)
I think for most people, they would implicitly understand that a tag is just a pointer to a commit SHA. I am clearly not most people :)
Your note, "The --target argument accepts commit SHAs, branch names, or tag names." made me go back and look at git documentation to dig in again to what a tag actually is so I could connect the dots that the tag is essentially the commit SHA.
I think it would be helpful to include tag in the documentation, e.g.
--target branch Target branch, tag or commit SHA (default: main branch)
or something to that effect.
In addition, on the same page, I think it would be helpful to add a link to documentation about what a Github Release is vs. just a tag. I started using the gh tool without actually truly understanding what a Github release is vs. just a tagged release.
Finally, considering your note ("Actually, I think that --target v0.2.0 in the last command isn't needed, because the v0.2.0 Release will automatically get tied to the v0.2.0 git tag if one already exists. The --target argument only has effect, I think, when the git tag doesn't yet exist in the repository.") -- understanding whether or not the --target tag isn't needed for certain will be helpful. I can and should test this for myself though!
Why did a short commit hash not work? It was not ambiguous, I am sure of it. Does the target need to be a specific length to be interpreted as a commit hash?
It would have been very helpful if gh release create --help or the error message mentioned this
@gilcrest This was all great feedback for us. Thank you! <3 We will try to improve the docs.
@megapctr I think that the short commit hash would not work as a commit SHA because it could be mis-interpreted as a branch name. E.g. deadbeef is a valid short commit hash, but is also valid words in English language and could possibly be a branch name. To avoid ambiguity, I think full commit SHAs are required. This would be also a good note to add to our docs.
@megapctr gh release create (with no --target) will target the latest state of the main branch as it is in the GitHub repository. Were you expecting that it targets HEAD as in, the currently checked out commit in your local repo?
@mislav yes, I expected it to target the current commit.
For context, I usually make two commits for a release: First updates the changelog to rename "dev" section to the version number. Second adds a new dev section to the changelog. Then I make a release targeting the first commit.
Knowing I need to specify --target with a full commit SHA lets me do what I need. I thought it may be helpful to the CLI team to point out how a similar tool (git tag) behaves differently in this regard.
@megapctr Thank you for explaining. Since gh release create can be run outside of a context of a local git repo (e.g. gh release create -R cli/cli), I do not think that we should take local HEAD as a default target, since sometimes there will be no local HEAD. However, your input will help us improve documentation on the matter!
@mislav: The --target argument accepts commit SHAs, branch names, or tag names.
Are tag names really supported? I just tried something like gh release create v0.2.0 --target v0.2.0 and got HTTP 422: Release.target_commitish is invalid. The docs also don't say anything about supporting tag names:
--target <branch> Target branch or full commit SHA (default: main branch)
@victorlin They should be. gh release create v0.2.0 --target v0.2.0 should have worked for you if a v0.2.0 tag exists in your remote repository. Was that the case? If so, you could try to use a fully qualified git ref: gh release create v0.2.0 --target refs/tags/v0.2.0. Update: no, that doesn't work.
Otherwise, I have a hunch that if you do gh release create v0.2.0 and not supply --target, the Release will be created for the existing git tag v0.2.0 anyway. So, you don't really need --target. Let us know if that worked!
@mislav thank you for your response! I would like to create a release only if the tag exists already, so I want to use --target to accomplish that. I just tried both --target <tag> and --target refs/tags/<tag> – neither worked. Created a separate issue for this: #5855
@victorlin Sorry for my previous misleading comment. I was just guessing that --target <tagname> could work, but since then I've learned that tag names are not valid input for this field. Right now, there doesn't seem a way to opt out of automated tag creation on release create. The best way to avoid a tag being auto-created is to ensure that a local tag is first pushed to a remote.
Activity
mislav commentedon Oct 12, 2020
Thanks for the feedback! ❤️
This does push a git tag to your GitHub repo, which shows up among "releases" for your repository, but it's not a full GitHub Release in a sense that you can edit the release notes in Markdown format or upload your own assets to it. The
gh release createcommand helps with creating a proper Release.I see! In case that you haven't created the
v0.2.0git tag yourself, the fact that you've created av0.2.0Release on GitHub will automatically create the underlyingv0.2.0git tag in your remote repository. The new tag will be created off the latest state of your default branch (e.g.main), but you can change that by passing the--targetparameter torelease createwith a specific commit SHA or a branch name where you want the new tag to point to.Finally, to fetch the new git tag locally, you can do
git fetch origin --tags.We can definitely make sure to document all this better in
release create, but other than just clearer documentation, is there something else that is confusing here or that you imagine should work differently?For example, would you expect us to automatically pull the newly created git tag locally after you've done
release create?gilcrest commentedon Oct 17, 2020
Super helpful information, thanks so much!
Would it be possible to add the tag locally and then use the tag for a target? e.g.
gh release create --target-tag v0.2.0or just recognize a semver pattern to enablegh release create --target v0.2.0Or does that not make sense? Pulling the tag locally after could work, but my typical flow, because of Go Modules, is to tag in my IDE and then push releases. I'm probably an outlier, I'm no Git wiz and can change my process!
Thanks again.
mislav commentedon Oct 19, 2020
@gilcrest It's absolutely possible to first create a tag locally and then create a release for it. The
--targetargument accepts commit SHAs, branch names, or tag names.Actually, I think that
--target v0.2.0in the last command isn't needed, because thev0.2.0Release will automatically get tied to thev0.2.0git tag if one already exists. The--targetargument only has effect, I think, when the git tag doesn't yet exist in the repository.Does this answer your questions? Is there something that you imagine gh should do differently around
release create? I'm hoping to define something actionable, if a change is needed, from this thread. 🙇gilcrest commentedon Oct 19, 2020
@mislav - again super helpful, thank you!
What was confusing for me was that your documentation at https://cli.github.com/manual/gh_release_create for --target is as follows:
I think for most people, they would implicitly understand that a tag is just a pointer to a commit SHA. I am clearly not most people :)
Your note, "The --target argument accepts commit SHAs, branch names, or tag names." made me go back and look at git documentation to dig in again to what a tag actually is so I could connect the dots that the tag is essentially the commit SHA.
I think it would be helpful to include tag in the documentation, e.g.
--target branch Target branch, tag or commit SHA (default: main branch)
or something to that effect.
In addition, on the same page, I think it would be helpful to add a link to documentation about what a Github Release is vs. just a tag. I started using the
ghtool without actually truly understanding what a Github release is vs. just a tagged release.Finally, considering your note ("Actually, I think that --target v0.2.0 in the last command isn't needed, because the v0.2.0 Release will automatically get tied to the v0.2.0 git tag if one already exists. The --target argument only has effect, I think, when the git tag doesn't yet exist in the repository.") -- understanding whether or not the --target tag isn't needed for certain will be helpful. I can and should test this for myself though!
I'm sorry to take up your time.
Thanks again for all your help!
Dan
ffigiel commentedon Nov 27, 2020
I ran into some issues when creating a release for a specific commit. Apologies if this belongs to a dedicated ticket.
and got
--targetas @mislav suggested, same problemWhy did a short commit hash not work? It was not ambiguous, I am sure of it. Does the target need to be a specific length to be interpreted as a commit hash?
It would have been very helpful if
gh release create --helpor the error message mentioned thismislav commentedon Dec 1, 2020
@gilcrest This was all great feedback for us. Thank you! <3 We will try to improve the docs.
@megapctr I think that the short commit hash would not work as a commit SHA because it could be mis-interpreted as a branch name. E.g.
deadbeefis a valid short commit hash, but is also valid words in English language and could possibly be a branch name. To avoid ambiguity, I think full commit SHAs are required. This would be also a good note to add to our docs.ffigiel commentedon Dec 1, 2020
@mislav thank you for clarification. Would it make sense for
gh release createto target HEAD by default, likegit tagdoes?mislav commentedon Dec 2, 2020
@megapctr
gh release create(with no--target) will target the latest state of the main branch as it is in the GitHub repository. Were you expecting that it targets HEAD as in, the currently checked out commit in your local repo?ffigiel commentedon Dec 2, 2020
@mislav yes, I expected it to target the current commit.
For context, I usually make two commits for a release: First updates the changelog to rename "dev" section to the version number. Second adds a new
devsection to the changelog. Then I make a release targeting the first commit.Knowing I need to specify
--targetwith a full commit SHA lets me do what I need. I thought it may be helpful to the CLI team to point out how a similar tool (git tag) behaves differently in this regard.mislav commentedon Dec 3, 2020
@megapctr Thank you for explaining. Since
gh release createcan be run outside of a context of a local git repo (e.g.gh release create -R cli/cli), I do not think that we should take local HEAD as a default target, since sometimes there will be no local HEAD. However, your input will help us improve documentation on the matter!victorlin commentedon Jun 23, 2022
Are tag names really supported? I just tried something like
gh release create v0.2.0 --target v0.2.0and gotHTTP 422: Release.target_commitish is invalid. The docs also don't say anything about supporting tag names:mislav commentedon Jun 27, 2022
@victorlin They should be.
Update: no, that doesn't work.gh release create v0.2.0 --target v0.2.0should have worked for you if av0.2.0tag exists in your remote repository. Was that the case? If so, you could try to use a fully qualified git ref:gh release create v0.2.0 --target refs/tags/v0.2.0.Otherwise, I have a hunch that if you do
gh release create v0.2.0and not supply--target, the Release will be created for the existing git tagv0.2.0anyway. So, you don't really need--target. Let us know if that worked!victorlin commentedon Jun 27, 2022
@mislav thank you for your response! I would like to create a release only if the tag exists already, so I want to use
--targetto accomplish that. I just tried both--target <tag>and--target refs/tags/<tag>– neither worked. Created a separate issue for this: #5855mislav commentedon Jul 11, 2022
@victorlin Sorry for my previous misleading comment. I was just guessing that
--target <tagname>could work, but since then I've learned that tag names are not valid input for this field. Right now, there doesn't seem a way to opt out of automated tag creation on release create. The best way to avoid a tag being auto-created is to ensure that a local tag is first pushed to a remote.SpaldingGreene commentedon Jul 11, 2022