Hub: Update default branch support

Created on 1 Dec 2019  路  8Comments  路  Source: github/hub

I have a project that relies on changing the default branch everyday. So, I wish I could use hub to update the remote default branch, as today I do it via GitHub web interface.

feature

Most helpful comment

@gibfahn Thanks for sharing your workaround. This smells like a bug with GitHub API. You're welcome to report it to our Support 馃檱

All 8 comments

You should be able to do this today with:

hub api -XPATCH repos/{owner}/{repo} -f default_branch=master

I'd just like to thank you, it worked perfectly.

I just had to set some environment variables, such as GIT_DIR and GIT_WORK_TREE, since I couldn't pass them as arguments (as I usually do with git binary).

@elisboa Did this not work for you?

hub --git-dir=/path/to/project/.git api ...

For me with hub 2.13 this works just as if I cd'd into /path/to/project and run hub api ... from there.

Tried this and ran into this issue (on GHE, unsure if still needed on public GitHub)

Solution in that link worked for me, namely:

hub api -XPATCH repos/{owner}/{repo} -f name={repo} -f default_branch=master

@gibfahn Thanks for sharing your workaround. This smells like a bug with GitHub API. You're welcome to report it to our Support 馃檱

Sorry for the delay. When I tried to run hub setting --git-dir and --work-tree it didin't work.

But actually, to set the default REMOTE branch, it wasn't needed, so I ran without setting it and it just worked, thanks :)

Just as a proof or evidence, here it goes below (it's a private repo):

hub api -XPATCH repos/elisboa/tmgit-files -f default_branch=2019.12.06
{"id":219029841,"node_id":"MDEwOlJlcG9zaXRvcnkyMTkwMjk4NDE=","name":"tmgit-files","full_name":"elisboa/tmgit-files","private":true,"owner":{"login":"elisboa","id":5649134,"node_id":"MDQ6VXNlcjU2NDkxMzQ=","avatar_url":"https://avatars3.githubusercontent.com/u/5649134?v=4","gravatar_id":"","url":"https://api.github.com/users/elisboa","html_url":"https://github.com/elisboa","followers_url":"https://api.github.com/users/elisboa/followers","following_url":"https://api.github.com/users/elisboa/following{/other_user}","gists_url":"https://api.github.com/users/elisboa/gists{/gist_id}","starred_url":"https://api.github.com/users/elisboa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elisboa/subscriptions","organizations_url":"https://api.github.com/users/elisboa/orgs","repos_url":"https://api.github.com/users/elisboa/repos","events_url":"https://api.github.com/users/elisboa/events{/privacy}","received_events_url":"https://api.github.com/users/elisboa/received_events","type":"User","site_admin":false},"html_url":"https://github.com/elisboa/tmgit-files","description":"My personal and private files","fork":false,"url":"https://api.github.com/repos/elisboa/tmgit-files","forks_url":"https://api.github.com/repos/elisboa/tmgit-files/forks","keys_url":"https://api.github.com/repos/elisboa/tmgit-files/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elisboa/tmgit-files/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elisboa/tmgit-files/teams","hooks_url":"https://api.github.com/repos/elisboa/tmgit-files/hooks","issue_events_url":"https://api.github.com/repos/elisboa/tmgit-files/issues/events{/number}","events_url":"https://api.github.com/repos/elisboa/tmgit-files/events","assignees_url":"https://api.github.com/repos/elisboa/tmgit-files/assignees{/user}","branches_url":"https://api.github.com/repos/elisboa/tmgit-files/branches{/branch}","tags_url":"https://api.github.com/repos/elisboa/tmgit-files/tags","blobs_url":"https://api.github.com/repos/elisboa/tmgit-files/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elisboa/tmgit-files/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elisboa/tmgit-files/git/refs{/sha}","trees_url":"https://api.github.com/repos/elisboa/tmgit-files/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elisboa/tmgit-files/statuses/{sha}","languages_url":"https://api.github.com/repos/elisboa/tmgit-files/languages","stargazers_url":"https://api.github.com/repos/elisboa/tmgit-files/stargazers","contributors_url":"https://api.github.com/repos/elisboa/tmgit-files/contributors","subscribers_url":"https://api.github.com/repos/elisboa/tmgit-files/subscribers","subscription_url":"https://api.github.com/repos/elisboa/tmgit-files/subscription","commits_url":"https://api.github.com/repos/elisboa/tmgit-files/commits{/sha}","git_commits_url":"https://api.github.com/repos/elisboa/tmgit-files/git/commits{/sha}","comments_url":"https://api.github.com/repos/elisboa/tmgit-files/comments{/number}","issue_comment_url":"https://api.github.com/repos/elisboa/tmgit-files/issues/comments{/number}","contents_url":"https://api.github.com/repos/elisboa/tmgit-files/contents/{+path}","compare_url":"https://api.github.com/repos/elisboa/tmgit-files/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elisboa/tmgit-files/merges","archive_url":"https://api.github.com/repos/elisboa/tmgit-files/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elisboa/tmgit-files/downloads","issues_url":"https://api.github.com/repos/elisboa/tmgit-files/issues{/number}","pulls_url":"https://api.github.com/repos/elisboa/tmgit-files/pulls{/number}","milestones_url":"https://api.github.com/repos/elisboa/tmgit-files/milestones{/number}","notifications_url":"https://api.github.com/repos/elisboa/tmgit-files/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elisboa/tmgit-files/labels{/name}","releases_url":"https://api.github.com/repos/elisboa/tmgit-files/releases{/id}","deployments_url":"https://api.github.com/repos/elisboa/tmgit-files/deployments","created_at":"2019-11-01T17:14:30Z","updated_at":"2019-12-05T23:00:37Z","pushed_at":"2019-12-06T18:00:35Z","git_url":"git://github.com/elisboa/tmgit-files.git","ssh_url":"[email protected]:elisboa/tmgit-files.git","clone_url":"https://github.com/elisboa/tmgit-files.git","svn_url":"https://github.com/elisboa/tmgit-files","homepage":null,"size":9594,"stargazers_count":0,"watchers_count":0,"language":"Shell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"2019.12.06","permissions":{"admin":true,"push":true,"pull":true},"allow_squash_merge":true,"allow_merge_commit":true,"allow_rebase_merge":true,"network_count":0,"subscribers_count":1}%

But actually, to set the default REMOTE branch, it wasn't needed, so I ran without setting it and it just worked, thanks :)

To change the default branch for the "origin" git remote (or any other remote) in your LOCAL git repo, you can use:

git remote set-head origin 2019.12.06

You probably want to do that in your local repo after you've successfully changed the default branch of the GitHub repository. 馃憤

Was this page helpful?
0 / 5 - 0 ratings