{"thread":{"id":"66757","subject":"[RFC] git branch: add -s/--switch to create and switch to a new branch","startedAt":"2026-11-03T15:34:09Z","lastAt":"2026-11-03T19:46:23Z","messageCount":3,"participants":["Johannes Welsch","Pushkar Singh","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"557325","messageId":"CA++gwosYFaOLD5nZjKUUFtp1ryezikqAsD6vu=uqBzOwyszASw@mail.gmail.com","threadId":"66757","inReplyTo":null,"subject":"[RFC] git branch: add -s/--switch to create and switch to a new branch","fromName":"Johannes Welsch","fromEmail":"johannes.welsch@googlemail.com","sentAt":"2026-11-03T15:34:09Z","receivedAt":"2026-11-03T15:34:09Z","isPatch":false,"sender":{"key":"johannes.welsch@googlemail.com","avatar":null},"body":"Hi,\n\nI'd like to propose adding a -s (--switch) option to `git branch`.\n\nIt makes sense semantically to create a branch and to also switch to it.\n\nCurrently, creating a new branch and immediately switching to it requires:\n\ngit switch -c newbranch\n\n\nI'd like to propose an alternative:\n\ngit branch -s newbranch\n\n\nMy reasoning is simple: when I want to create a new branch, git branch\nis naturally the command I think of.\n\nI want to create a branch and also switch to it. For me, switching is\nan additional action when creating the branch, rather than the primary\noperation.\n\nThe proposed option would behave like git switch -c, creating the\nbranch and switching to it in one operation. It would fail if the\nbranch already exists, just as git switch -c does.\n\nI understand that git switch -c already supports this functionality,\nbut I think the alternative syntax would be more intuitive for users\nwho approach the operation from the branch-creation perspective.\n\nThanks!\nJohannes\n\n"},{"id":"557345","messageId":"20261103175721.1148-1-pushkarkumarsingh1970@gmail.com","threadId":"66757","inReplyTo":"CA++gwosYFaOLD5nZjKUUFtp1ryezikqAsD6vu=uqBzOwyszASw@mail.gmail.com","subject":"Re: [RFC] git branch: add -s/--switch to create and switch to a new branch","fromName":"Pushkar Singh","fromEmail":"pushkarkumarsingh1970@gmail.com","sentAt":"2026-11-03T17:57:21Z","receivedAt":"2026-11-03T17:57:21Z","isPatch":false,"sender":{"key":"pushkarkumarsingh1970@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173247767?v=4"},"body":"Hi Johannes,\n\n[snip]\n> when I want to create a new branch, git branch is naturally the command I think of. I want to create a branch and also switch to it.\n\nI get your point, but wouldn't this introduce some overlap between \"git branch\" and \"git switch\"?\n\nCurrently, we already have \"git branch <name>\" to create a branch without switching to it, and \"git switch <name>\" to switch to an existing branch. If you want to create a new branch and switch to it immediately, \"git switch -c <name>\" already does that.\n\nIn fact, the git branch documentation[1] itself suggests using \"git switch -c\" for exactly this use case.\n\n[snip]\n> switching is an additional action when creating the branch, rather than the primary operation.\n\nI understand where you're coming from, but isn't this separation between creating and switching branches one of the reasons git switch was introduced in the first place?\n\nWould adding this functionality to \"git branch\" make that distinction a little less clear?\n\nThanks!\n\nPushkar\n\n---\n\n[1]: https://git-scm.com/docs/git-branch?#_notes\n\n"},{"id":"557365","messageId":"xmqq7bit7l68.fsf@gitster.g","threadId":"66757","inReplyTo":"CA++gwosYFaOLD5nZjKUUFtp1ryezikqAsD6vu=uqBzOwyszASw@mail.gmail.com","subject":"Re: [RFC] git branch: add -s/--switch to create and switch to a new branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-03T19:46:23Z","receivedAt":"2026-11-03T19:46:23Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Welsch <johannes.welsch@googlemail.com> writes:\n\n> I'd like to propose adding a -s (--switch) option to `git branch`.\n>\n> It makes sense semantically to create a branch and to also switch to it.\n\nWhy is \"git checkout -b <new-branch-name> [<where-the-branch-begins]\" \nnot sufficient?\n\n"}]}