René's URL Explorer Experiment


Title: project creation ignores default_branch and default-branch contradicts documentation · Issue #3181 · python-gitlab/python-gitlab · GitHub

Open Graph Title: project creation ignores default_branch and default-branch contradicts documentation · Issue #3181 · python-gitlab/python-gitlab

X Title: project creation ignores default_branch and default-branch contradicts documentation · Issue #3181 · python-gitlab/python-gitlab

Description: Description of the problem, including code/CLI snippet I've spent a couple hours on this, but basically when creating a project from the python package or from CLI, the default_branch (in SDK) and --default-branch settings are ignored, g...

Open Graph Description: Description of the problem, including code/CLI snippet I've spent a couple hours on this, but basically when creating a project from the python package or from CLI, the default_branch (in SDK) and ...

X Description: Description of the problem, including code/CLI snippet I've spent a couple hours on this, but basically when creating a project from the python package or from CLI, the default_branch (in SDK) ...

Opengraph URL: https://github.com/python-gitlab/python-gitlab/issues/3181

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"project creation ignores default_branch and default-branch contradicts documentation","articleBody":"## Description of the problem, including code/CLI snippet\n\nI've spent a couple hours on this, but basically when creating a project from the python package or from CLI, the `default_branch` (in SDK) and `--default-branch` settings are ignored, \n```\n    group_id = gl.groups.list(search=namespace)[0].id\n    project = gl.projects.create(\n        {\n            'name': project_name,\n            'path': repo_name,\n            'namespace_id': group_id,\n            'default_branch': 'master',\n        }\n    )\n```\n\nThe same thing happens from CLI: \n```\ngitlab project create --name myproj --path myrepo --namespace-id GROUP_ID --default-branch master\n```\n\n## Expected Behavior\n\nAfter creation as described, the project object should show `default_branch` == \"master\" and the branch should show as protected. \n\nRegardless of being created from CLI or SDK. \n\n## Actual Behavior\n\nThe CLI and SDK both show that the default branch is \"main\". The console says that a default branch cannot be set on an empty repo. \n\nIf this is not possible because of how the gitlab package is a thin wrapper over gitlab REST API, the readme in this repo should at least mention such discrepencies between the docs (auto generated from the REST API, shown in the CLI --help output) and actual behavior.\n\n## Workaround (possibly a hack) \n\nCall these 2 functions, in order: \n```\ndef gitlab_project_repo_setup_content(project):\n    try:\n        project.files.get('README.md', ref='main')\n    except GitlabGetError:\n        print('Creating file in repo')\n        project.files.create(\n            {\n                'file_path': 'README.md',\n                'branch': 'main',\n                'content': '# Placeholder file',\n                'commit_message': 'Add README to initialize repository',\n            }\n        )\n\ndef gitlab_project_set_default_branch(project):\n    \"\"\"\n    Workaround for gitlab default branch can only be changed after there is content added:\n    if you set default_branch in the project.create(), it gets ignored, ie project.default_branch will\n    still be 'main'. Same goes for command line. It appears that there HAS to be at least one\n    file in the reop for the default branch to be changed.\n    \"\"\"\n    # verify that that readme exists, this will raise exception if not:\n    project.files.get('README.md', ref='main')\n\n    project.branches.create({'branch': 'master', 'ref': 'main'})\n    project.default_branch = 'master'\n    project.save()\n\n    project.protectedbranches.create({'name': 'master'})\n    project.protectedbranches.delete('main')\n    project.branches.delete('main')\n```\n\nAfter running these 2, the git repo will have only master branch, and gitlab console will show this and that it is default and protected, \n\n## Specifications\n\n  - python-gitlab version: 5.6.0\n  - Gitlab server version (or gitlab.com): gitlab.com\n","author":{"url":"https://github.com/schollii","@type":"Person","name":"schollii"},"datePublished":"2025-04-26T17:07:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/3181/python-gitlab/issues/3181"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:150ae98d-7f45-0036-7f9e-9f1280be29fa
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBB32:119AFD:18793DB:21399B8:6973F26D
html-safe-nonce6a0bce4c80642698fa740ace796c51b89a0349babbcdcd6ec316bc312407e117
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjMyOjExOUFGRDoxODc5M0RCOjIxMzk5Qjg6Njk3M0YyNkQiLCJ2aXNpdG9yX2lkIjoiODUxMjczNjY3OTc5MjIxMDU0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacffc8ad196b8016b86616c83e91aad11963b00787acdaf5958f6c793517c2bc30
hovercard-subject-tagissue:3022134603
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-gitlab/python-gitlab/3181/issue_layout
twitter:imagehttps://opengraph.githubassets.com/5014028bc735a0defe483de665be163bc754308bdf61a394ba0aa5d079b70fc5/python-gitlab/python-gitlab/issues/3181
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/5014028bc735a0defe483de665be163bc754308bdf61a394ba0aa5d079b70fc5/python-gitlab/python-gitlab/issues/3181
og:image:altDescription of the problem, including code/CLI snippet I've spent a couple hours on this, but basically when creating a project from the python package or from CLI, the default_branch (in SDK) and ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameschollii
hostnamegithub.com
expected-hostnamegithub.com
None99794f659b61e238a7ec37595eeb36b54a0ba1f2ae246f51ccb8ac5e4f08812e
turbo-cache-controlno-preview
go-importgithub.com/python-gitlab/python-gitlab git https://github.com/python-gitlab/python-gitlab.git
octolytics-dimension-user_id28886265
octolytics-dimension-user_loginpython-gitlab
octolytics-dimension-repository_id8077625
octolytics-dimension-repository_nwopython-gitlab/python-gitlab
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id8077625
octolytics-dimension-repository_network_root_nwopython-gitlab/python-gitlab
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8b15a65f03216f079a4ae509ff400d3e2ce03b58
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/issues/3181#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-gitlab%2Fpython-gitlab%2Fissues%2F3181
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-gitlab%2Fpython-gitlab%2Fissues%2F3181
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python-gitlab%2Fpython-gitlab
Reloadhttps://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/issues/3181
Reloadhttps://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/issues/3181
Reloadhttps://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/issues/3181
python-gitlab https://patch-diff.githubusercontent.com/python-gitlab
python-gitlabhttps://patch-diff.githubusercontent.com/python-gitlab/python-gitlab
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-gitlab%2Fpython-gitlab
Fork 675 https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-gitlab%2Fpython-gitlab
Star 2.4k https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-gitlab%2Fpython-gitlab
Code https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab
Issues 26 https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/issues
Pull requests 11 https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/pulls
Discussions https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/discussions
Actions https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/actions
Projects 0 https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/projects
Security 0 https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/security
Insights https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/pulse
Code https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab
Issues https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/issues
Pull requests https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/pulls
Discussions https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/discussions
Actions https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/actions
Projects https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/projects
Security https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/security
Insights https://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/python-gitlab/python-gitlab/issues/3181
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/python-gitlab/python-gitlab/issues/3181
project creation ignores default_branch and default-branch contradicts documentationhttps://patch-diff.githubusercontent.com/python-gitlab/python-gitlab/issues/3181#top
https://github.com/schollii
https://github.com/schollii
scholliihttps://github.com/schollii
on Apr 26, 2025https://github.com/python-gitlab/python-gitlab/issues/3181#issue-3022134603
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.