Repository navigation
api: create branches and tags - #8566
Merged
Merged
Conversation
This was referenced Nov 15, 2026
Closed
4 tasks done
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
unknwon
force-pushed
the
api-create-branch-tag
branch
from
November 17, 2026 23:53
1012e55 to
6702533
Compare
unknwon
force-pushed
the
api-create-branch-tag
branch
from
November 18, 2026 03:12
6702533 to
1e357b8
Compare
unknwon
force-pushed
the
api-create-branch-tag
branch
from
November 18, 2026 03:17
1e357b8 to
f4e673d
Compare
POST /repos/{owner}/{repo}/branches and /repos/{owner}/{repo}/tags create a
branch or lightweight tag named "name" at "target", which is a branch, tag or
commit and defaults to the default branch. The reference is pushed as the
user, so the hooks of the repository record the activity and fire the create
and push webhooks like a "git push" would.
Meldiron proposed and implemented creating tags through the API in #8212. Co-authored-by: Meldiron <[email protected]>
… to branches first Creating a branch or tag whose name clashes with an existing reference path, e.g., "feature" next to "feature/base", and concurrent requests for the same name now respond 422 instead of 500 or recording the creation more than once. A target names a branch before a tag of the same name, like the rest of the API, and a range such as "a..b" is not a target.
The push reports a reference that is taken, so creating one needs no lock or check beforehand, and a reference created by a Git push in the meantime is no longer recorded twice. Git before 2.51 gives no specific reason for a conflict, so the reference is checked after such a failed push.
unknwon
force-pushed
the
api-create-branch-tag
branch
from
November 18, 2026 04:16
5788ced to
0d998b4
Compare
4 tasks done
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the pull request
Stacked on #8454.
Adds two endpoints, both requiring write access:
POST /repos/{owner}/{repo}/branchesPOST /repos/{owner}/{repo}/tagsBoth take
{"name": "...", "target": "..."}.targetis a branch, tag (annotated tags are peeled) or commit SHA, and defaults to the default branch. They respond201with the same body as getting the branch or listing the tag.The reference is pushed as the user from a temporary repository, the same way the web editor commits. So the repository's hooks run: the activity feed shows the new branch or tag, and the
createandpushwebhooks fire as they would for agit push.Errors:
422: invalid name (git check-ref-format, plus tag names starting with-or equal toHEAD), name already taken, or target not found.403: mirror repository, or no write access.The API reference documents both endpoints. This supersedes #8212 by @Meldiron, which was closed for inactivity.
Link to the issue: Closes #8213, closes #8209
Checklist
Test plan
Added
TestRepository_IsValidTagName. Ran a local server with SQLite and a webhook receiver forcreateandpush:nested/namefrom a branch201, refs created on the default branch's commit201, lightweight tags on the peeled commit422already exists-x,a..b,HEAD,x.lock,@{-1}; tag-x,HEAD,v1/,a b422invalid namenope,--output=/tmp/pwned, a missing SHA422target does not exist, no file written422targetmaindoes not exist403403, then201GET /branchesandGET /tagslist the new references. Every creation added a feed entry (create branch, or push tag) for the right user. The receiver gotcreatewithref_typebranchortagfor each, pluspushfor branches. No errors were logged.moon run gogs:lintreports 0 issues.