{"thread":{"id":"30205","subject":"Why can't git open empty branches ?","startedAt":"2012-04-11T10:35:23Z","lastAt":"2012-04-11T14:16:37Z","messageCount":8,"participants":["Hadmut Danisch","Jonathan Nieder","Matthieu Moy","Holger Hellmuth"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"188940","messageId":"4F855E6B.4010504@danisch.de","threadId":"30205","inReplyTo":null,"subject":"Why can't git open empty branches ?","fromName":"Hadmut Danisch","fromEmail":"hadmut@danisch.de","sentAt":"2012-04-11T10:35:23Z","receivedAt":"2012-04-11T10:35:23Z","isPatch":false,"sender":{"key":"hadmut@danisch.de","avatar":null},"body":"Hi,\n\nwhen creating a new branch in git, it is by default filled with the\ncontents of the current branch.\n\nSometimes a new but empty branch is needed. There are plenty of\ninstructions in the web to achieve this with „dirty tricks”, i.e. fiddle\naround with git's internals. Which is poor design.\n\n\n\nWhy doesn't git's branch command support opening empty branches in a\nclean an natural way?\n\n\n\nregards\nHadmut\n"},{"id":"188942","messageId":"20120411105906.GA19823@burratino","threadId":"30205","inReplyTo":"4F855E6B.4010504@danisch.de","subject":"Re: Why can't git open empty branches ?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-04-11T10:59:06Z","receivedAt":"2012-04-11T10:59:06Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hadmut Danisch wrote:\n\n> when creating a new branch in git, it is by default filled with the\n> contents of the current branch.\n>\n> Sometimes a new but empty branch is needed. There are plenty of\n> instructions in the web to achieve this with „dirty tricks”, i.e. fiddle\n> around with git's internals.\n\n\tgit init ../unrelated-topic\n\tcd ../unrelated-topic\n\thack away...\n\tgit commit\n\tcd -\n\tgit fetch ../unrelated-topic master:<new branch>\n\nOr:\n\n\tgit checkout --orphan <new branch>\n\tgit rm -fr .\n\thack away...\n\nPlease feel free to contact the authors of the instructions you found\non the web to fix them.\n\nThanks and hope that helps,\nJonathan\n"},{"id":"188943","messageId":"4F8565BC.1070701@danisch.de","threadId":"30205","inReplyTo":"20120411105906.GA19823@burratino","subject":"Re: Why can't git open empty branches ?","fromName":"Hadmut Danisch","fromEmail":"hadmut@danisch.de","sentAt":"2012-04-11T11:06:36Z","receivedAt":"2012-04-11T11:06:36Z","isPatch":false,"sender":{"key":"hadmut@danisch.de","avatar":null},"body":"Am 11.04.2012 12:59, schrieb Jonathan Nieder:\n> \tgit checkout --orphan <new branch>\n> \tgit rm -fr .\n\n\n\nI would have expected something more obvious and intuitive like\n\n  git branch --empty\n\n\n\nIt is not really plausible to create a new branch by checking out a\nnon-existing one.\n\nHowever, this helps. Thanks.\n"},{"id":"188945","messageId":"vpq7gxmzf75.fsf@bauges.imag.fr","threadId":"30205","inReplyTo":"4F8565BC.1070701@danisch.de","subject":"Re: Why can't git open empty branches ?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-04-11T11:21:50Z","receivedAt":"2012-04-11T11:21:50Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Hadmut Danisch <hadmut@danisch.de> writes:\n\n> It is not really plausible to create a new branch by checking out a\n> non-existing one.\n\n... but it is hardly useful to create a new branch unless you want to\ncheck it out.\n\nI think the most common way to create a branch with Git is \"git checkout\n-b new-branch\", which does the creation+checkout in a single command.\n\"git checkout --orphan\" is the natural extension of it.\n\nBTW, it is rarely good practice to create an empty branch in an existing\nrepository. You'll have different branches that do not share any\nhistory, and they would likely be better in separate repositories (or at\nleast, be in separate local repositories, pushed to the same remote bare\nrepository, in which case you don't need anything special, just \"git\ninit\" and \"git push\"). That doesn't mean you shouldn't do it, but just\nthat you may want to think twice before doing it ;-).\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"188948","messageId":"4F856F67.4000609@danisch.de","threadId":"30205","inReplyTo":"vpq7gxmzf75.fsf@bauges.imag.fr","subject":"Re: Why can't git open empty branches ?","fromName":"Hadmut Danisch","fromEmail":"hadmut@danisch.de","sentAt":"2012-04-11T11:47:51Z","receivedAt":"2012-04-11T11:47:51Z","isPatch":false,"sender":{"key":"hadmut@danisch.de","avatar":null},"body":"Am 11.04.2012 13:21, schrieb Matthieu Moy:\n> BTW, it is rarely good practice to create an empty branch in an existing\n> repository. You'll have different branches that do not share any\n> history, and they would likely be better in separate repositories (or at\n> least, be in separate local repositories, pushed to the same remote bare\n> repository, in which case you don't need anything special, just \"git\n> init\" and \"git push\"). That doesn't mean you shouldn't do it, but just\n> that you may want to think twice before doing it ;-).\n\nThat's a pretty good point for discussion.\n\n\nSometimes people are working on different sorts of information, that are\nnevertheless closely related, e.g. open source software and the web\npages describing it (like in git hub), or a web server tree and the\nsoftware generating it. They are related, but do not logically share a\nhistory.\n\n\nCreating independent branches by pushing two separates into a single\nremote bare is a nice idea, but if I understood git correctly, the very\nfirst commit in a repos is always to the master branch, where you have\ntwo masters trying to push into the shared remote bare. This is\nobviously solvable if you use the correct commands and maybe delete and\nre-clone the repos, but this is all overcomplicated and non-trivial.\nNothing I could do without reading manuals.\n\nSo your proposal might work perfectly, but in my eyes it is error prone\nand not user friendly.\n\nregards\n"},{"id":"188955","messageId":"20120411121907.GA30340@burratino","threadId":"30205","inReplyTo":"4F856F67.4000609@danisch.de","subject":"Re: Why can't git open empty branches ?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-04-11T12:19:07Z","receivedAt":"2012-04-11T12:19:07Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hadmut Danisch wrote:\n\n> Creating independent branches by pushing two separates into a single\n> remote bare is a nice idea, but if I understood git correctly, the very\n> first commit in a repos is always to the master branch, where you have\n> two masters trying to push into the shared remote bare. This is\n> obviously solvable if you use the correct commands and maybe delete and\n> re-clone the repos, but this is all overcomplicated and non-trivial.\n> Nothing I could do without reading manuals.\n\nI suppose you had to read the manual to learn the \"git commit\" and\n\"git branch -m\" commands, yes.  But what's wrong with that, or how\ncould we fix it?\n\n\tgit init code\n\tcd code\n\t... hack away ...\n\tgit remote add origin <url>\n\tgit push -u origin master\n\tcd ..\n\n\tgit init website\n\tcd website\n\t... hack away ...\n\tgit branch -m website\n\tgit remote add origin <url>\n\tgit push -u origin website\n\tcd ..\n\nI wonder if there is a potential documentation or error message update\nlurking behind these questions.\n\nHope that helps,\nJonathan\n"},{"id":"188956","messageId":"vpqbomyv4t3.fsf@bauges.imag.fr","threadId":"30205","inReplyTo":"4F856F67.4000609@danisch.de","subject":"Re: Why can't git open empty branches ?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-04-11T12:19:52Z","receivedAt":"2012-04-11T12:19:52Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Hadmut Danisch <hadmut@danisch.de> writes:\n\n> e.g. open source software and the web pages describing it (like in git\n> hub), or a web server tree and the software generating it. They are\n> related, but do not logically share a history.\n\nIn these cases, you'll want to have two working directories, if only to\navoid:\n\ngit checkout documentation\n# fix a typo\ngit commit\ngit checkout code\nmake\n# complete rebuild triggered.\n\n> Creating independent branches by pushing two separates into a single\n> remote bare is a nice idea, but if I understood git correctly, the very\n> first commit in a repos is always to the master branch,\n\nNot necessarily. I don't see an option in \"git init\" to change the\ndefault branch name, but you can\n\ngit init foo\ncd foo\ngit checkout -b whatever-branch-name\n\nand work.\n\nOtherwise, you can have a branch that is locally called \"master\", and\npush it as another name (but that is probably the \"error prone\" in your\nmessage ;-) ).\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"188961","messageId":"4F859245.908@ira.uka.de","threadId":"30205","inReplyTo":"4F856F67.4000609@danisch.de","subject":"Re: Why can't git open empty branches ?","fromName":"Holger Hellmuth","fromEmail":"hellmuth@ira.uka.de","sentAt":"2012-04-11T14:16:37Z","receivedAt":"2012-04-11T14:16:37Z","isPatch":false,"sender":{"key":"hellmuth@ira.uka.de","avatar":null},"body":"Hi Hadmut ;-)\n\nOn 11.04.2012 13:47, Hadmut Danisch wrote:\n> Creating independent branches by pushing two separates into a single\n> remote bare is a nice idea, but if I understood git correctly, the very\n> first commit in a repos is always to the master branch, where you have\n\nAFAIK the only thing that makes master the initial branch is the file \n.git/HEAD that points to master after you \"git init\". This is not hardcoded.\n\n > So your proposal might work perfectly, but in my eyes it is error\n > prone and not user friendly.\n\nSerious errors should not happen since the bare repo on the server is \ncreated with the flag denyNonFastForwards. So even if you had a master \nbranch in both repos, only one of them, the first one, would succeed in \npushing to the server, a push of the second one would give you an error \nmessage. Maybe not user friendly, but safe.\n"}]}