Title: push_files leaves an orphan branch at the default branch's head when the push fails · Issue #3755 · github/github-mcp-server · GitHub
Open Graph Title: push_files leaves an orphan branch at the default branch's head when the push fails · Issue #3755 · github/github-mcp-server
X Title: push_files leaves an orphan branch at the default branch's head when the push fails · Issue #3755 · github/github-mcp-server
Description: Describe the bug When branch does not exist, push_files creates it from the default branch first (createReferenceFromDefaultBranch) and only then builds the tree and commit. If the tree or commit step fails, the new ref is not rolled bac...
Open Graph Description: Describe the bug When branch does not exist, push_files creates it from the default branch first (createReferenceFromDefaultBranch) and only then builds the tree and commit. If the tree or commit s...
X Description: Describe the bug When branch does not exist, push_files creates it from the default branch first (createReferenceFromDefaultBranch) and only then builds the tree and commit. If the tree or commit s...
Opengraph URL: https://github.com/github/github-mcp-server/issues/3755
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"push_files leaves an orphan branch at the default branch's head when the push fails","articleBody":"### Describe the bug\n\nWhen `branch` does not exist, `push_files` creates it from the default branch first (`createReferenceFromDefaultBranch`) and only then builds the tree and commit. If the tree or commit step fails, the new ref is not rolled back. The caller gets an error, but a branch pointing at the default branch's head stays behind. A retry then pushes onto that leftover branch, and it shows up in branch lists.\n\nWhen the branch already exists, the same failure leaves no partial commit, so only the new-branch path is affected.\n\nSilently creating a branch that doesn't exist is already raised as a question in #3473 (item 6). This issue is only about the ref left behind when the push then fails.\n\nCode (main 99d6d650, unchanged since v2.1.0): `pkg/github/repositories.go:1767-1772` (ref created when the branch is missing), `:1795-1800` (same for the empty-repo path), then `CreateTree` at `:1809` and `CreateCommit`/`UpdateRef` after it. Helper: `pkg/github/repositories_helper.go:75`. Open PR #3288 keeps the ensure-ref-first order (`ensurePushFilesBranchRef`), so it would not change this.\n\n### Affected version\n\nv2.1.0 (image `sha256:f6056fc1…0f8a`, commit 4bcdcdf8) and main nightly (image `sha256:48bc16d0…338f`, revision 99d6d650).\n\n### Steps to reproduce the behavior\n\n1. Make sure the branch `new-branch` does not exist.\n2. Call it with one valid file and one path that `CreateTree` rejects:\n ```json\n {\"name\":\"push_files\",\"arguments\":{\"owner\":\"OWNER\",\"repo\":\"REPO\",\"branch\":\"new-branch\",\"message\":\"push\",\"files\":[{\"path\":\"p4/ok.txt\",\"content\":\"ok\"},{\"path\":\".git/config\",\"content\":\"x\"}]}}\n ```\n3. Result: `isError` with `failed to create tree: tree.path contains a malformed path component`.\n4. `GET /repos/OWNER/REPO/git/ref/heads/new-branch` returns 200, and the branch points at the default branch's head commit.\n\n### Expected vs actual behavior\n\nExpected: a failed push leaves the repository unchanged, with no new branch.\n\nActual: the error is returned and an orphan branch exists at the default branch's head.\n\nSuggested fix: tree and commit objects don't need a ref. Create the tree and the commit (parent = default branch head) first, then create the new ref directly at the new commit. Alternatively, delete the ref on any later failure.\n\n### Logs\n\n```\npush_files branch=new-branch -> ISERROR failed to create tree: tree.path contains a malformed path component\nGET git/ref/heads/new-branch -> 200, object.sha = faf1b251… (= default branch head) [v2.1.0 and main]\n```\n\nFound during an independent audit of v2.1.0 on a throwaway org and private test repo. Prepared with AI assistance (Claude Code); reproduced by two independent test runs before filing.\n","author":{"url":"https://github.com/rafe-walker","@type":"Person","name":"rafe-walker"},"datePublished":"2026-11-09T05:53:56Z","url":"https://github.com/github/github-mcp-server/issues/3755"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6d77c8d8-4f11-c7fc-45e8-c9fe72599024 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB4E:4265D:930EBE:C7C67C:6B05F003 |
| html-safe-nonce | bf161a406fc30603ec8044c848b94e16e32c251bfb2420b94390adbc9a7f235d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjRFOjQyNjVEOjkzMEVCRTpDN0M2N0M6NkIwNUYwMDMiLCJ2aXNpdG9yX2lkIjoiMzM2MjM0MDUxMTI1MTAzNDExNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 266bdb9dd2acce4a57823ece51efd35a85686178561996a9de3995afd33950f3 |
| hovercard-subject-tag | issue:6280784303 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/github/github-mcp-server/3755/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3bb44bac5d99814190338e404f90a73c7403a4b29f77db73cbc5deb64cb8af4d/github/github-mcp-server/issues/3755 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3bb44bac5d99814190338e404f90a73c7403a4b29f77db73cbc5deb64cb8af4d/github/github-mcp-server/issues/3755 |
| og:image:alt | Describe the bug When branch does not exist, push_files creates it from the default branch first (createReferenceFromDefaultBranch) and only then builds the tree and commit. If the tree or commit s... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rafe-walker |
| hostname | github.com |
| expected-hostname | github.com |
| None | c214754a6652274794ed4e054a7b71be999d69843f103ba54893001d45010ece |
| turbo-cache-control | no-preview |
| go-import | github.com/github/github-mcp-server git https://github.com/github/github-mcp-server.git |
| octolytics-dimension-user_id | 9919 |
| octolytics-dimension-user_login | github |
| octolytics-dimension-repository_id | 942771284 |
| octolytics-dimension-repository_nwo | github/github-mcp-server |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 942771284 |
| octolytics-dimension-repository_network_root_nwo | github/github-mcp-server |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7d164a4e71eb333b2b17fd5b17e18efb7855505c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width