{"thread":{"id":"22995","subject":"How do you switch branches in a bare repo?","startedAt":"2010-03-12T06:26:42Z","lastAt":"2010-03-14T06:52:51Z","messageCount":8,"participants":["Adam Nielsen","Johannes Sixt","Michael Witten","Jonathan Nieder","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"136644","messageId":"4B99DEA2.6050104@uq.edu.au","threadId":"22995","inReplyTo":null,"subject":"How do you switch branches in a bare repo?","fromName":"Adam Nielsen","fromEmail":"adam.nielsen@uq.edu.au","sentAt":"2010-03-12T06:26:42Z","receivedAt":"2010-03-12T06:26:42Z","isPatch":false,"sender":{"key":"adam.nielsen@uq.edu.au","avatar":"https://gravatar.com/avatar/f5ed2feee93ef40d640c5a4e43fcb9ac9a916e289d65d9614e1742089e73fb62?d=mp&s=160"},"body":"Hi all,\n\nI want to remove some commits (with git reset) from a bare repo, but \nthey're not in the master branch and I can't figure out how to change \nbranches:\n\n$ git checkout newbranch\nfatal: This operation must be run in a work tree\n\nI've tried running the reset locally and pushing the change (with -f) \nbut that doesn't work either, and Google isn't being much help.\n\nHow do you switch between branches in a bare repo?\n\nMany thanks,\nAdam.\n\n(Please CC)\n"},{"id":"136648","messageId":"4B99E5DD.3020005@viscovery.net","threadId":"22995","inReplyTo":"4B99DEA2.6050104@uq.edu.au","subject":"Re: How do you switch branches in a bare repo?","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-03-12T06:57:33Z","receivedAt":"2010-03-12T06:57:33Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Adam Nielsen schrieb:\n> I want to remove some commits (with git reset) from a bare repo, but\n> they're not in the master branch and I can't figure out how to change\n> branches:\n> \n> $ git checkout newbranch\n> fatal: This operation must be run in a work tree\n> \n> I've tried running the reset locally and pushing the change (with -f)\n> but that doesn't work either, and Google isn't being much help.\n> \n> How do you switch between branches in a bare repo?\n\nYou don't have to. This should work:\n\n   git push -f . newbranch~2:newbranch\n\nwill remove the last two commits at the tip of 'newbranch'.\n\nOf course, you can do the push from any other repository as long as you\nare allowed to do non-fast-forward pushes into the bare repository.\n\n-- Hannes\n"},{"id":"136649","messageId":"4B99E957.60905@uq.edu.au","threadId":"22995","inReplyTo":"4B99E5DD.3020005@viscovery.net","subject":"Re: How do you switch branches in a bare repo?","fromName":"Adam Nielsen","fromEmail":"adam.nielsen@uq.edu.au","sentAt":"2010-03-12T07:12:23Z","receivedAt":"2010-03-12T07:12:23Z","isPatch":false,"sender":{"key":"adam.nielsen@uq.edu.au","avatar":"https://gravatar.com/avatar/f5ed2feee93ef40d640c5a4e43fcb9ac9a916e289d65d9614e1742089e73fb62?d=mp&s=160"},"body":">> How do you switch between branches in a bare repo?\n> \n> You don't have to. This should work:\n> \n>    git push -f . newbranch~2:newbranch\n> \n> will remove the last two commits at the tip of 'newbranch'.\n> \n> Of course, you can do the push from any other repository as long as you\n> are allowed to do non-fast-forward pushes into the bare repository.\n\nThanks for the suggestion!  Unfortunately it looks like I'm not allowed \nto do non-fast-forward pushes into my own repository because I keep \ngetting this error:\n\nerror: denying non-fast-forward refs/heads/newbranch (you should pull first)\n  ! [remote rejected] newbranch~2 -> newbranch (non-fast-forward)\n\nI tried using a + in front of the branch name as recommended by the \nmanpage but it didn't change anything :-(\n\nAny further suggestions?\n\nThanks again,\nAdam.\n"},{"id":"136652","messageId":"4B99EE7C.4060902@viscovery.net","threadId":"22995","inReplyTo":"4B99E957.60905@uq.edu.au","subject":"Re: How do you switch branches in a bare repo?","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-03-12T07:34:20Z","receivedAt":"2010-03-12T07:34:20Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Adam Nielsen schrieb:\n> Thanks for the suggestion!  Unfortunately it looks like I'm not allowed\n> to do non-fast-forward pushes into my own repository because I keep\n> getting this error:\n> \n> error: denying non-fast-forward refs/heads/newbranch (you should pull\n> first)\n>  ! [remote rejected] newbranch~2 -> newbranch (non-fast-forward)\n\nPerhaps non-fast-forwards are denied for a reason?\n\nIf not, then you can enable them by setting receive.denynonfastforwards to\nfalse in the bare repository.\n\n-- Hannes\n"},{"id":"136653","messageId":"4B99EF6F.90207@uq.edu.au","threadId":"22995","inReplyTo":"4B99EE7C.4060902@viscovery.net","subject":"Re: How do you switch branches in a bare repo?","fromName":"Adam Nielsen","fromEmail":"adam.nielsen@uq.edu.au","sentAt":"2010-03-12T07:38:23Z","receivedAt":"2010-03-12T07:38:23Z","isPatch":false,"sender":{"key":"adam.nielsen@uq.edu.au","avatar":"https://gravatar.com/avatar/f5ed2feee93ef40d640c5a4e43fcb9ac9a916e289d65d9614e1742089e73fb62?d=mp&s=160"},"body":"> Perhaps non-fast-forwards are denied for a reason?\n> \n> If not, then you can enable them by setting receive.denynonfastforwards to\n> false in the bare repository.\n\nAh, that did the trick!  Although it was actually \nreceive.denyNonFastforwards for me (adding the lowercase option had no \neffect, I had to edit the fancy-case version.)\n\nBut that allowed the push to work and I have gotten rid of my unwanted \ncommits, so thanks a lot for your help!\n\nCheers,\nAdam.\n"},{"id":"136655","messageId":"b4087cc51003120009o7bd99609w996de02b732fbbd9@mail.gmail.com","threadId":"22995","inReplyTo":"4B99DEA2.6050104@uq.edu.au","subject":"Re: [Improvement?] How do you switch branches in a bare repo?","fromName":"Michael Witten","fromEmail":"mfwitten@gmail.com","sentAt":"2010-03-12T08:09:53Z","receivedAt":"2010-03-12T08:09:53Z","isPatch":false,"sender":{"key":"mfwitten@gmail.com","avatar":"https://avatars.githubusercontent.com/u/597101?v=4"},"body":"On Fri, Mar 12, 2010 at 00:26, Adam Nielsen <adam.nielsen@uq.edu.au> wrote:\n> Hi all,\n>\n> I want to remove some commits (with git reset) from a bare repo, but they're\n> not in the master branch and I can't figure out how to change branches:\n>\n> $ git checkout newbranch\n> fatal: This operation must be run in a work tree\n\nCommands like \"git checkout\" and \"git reset\" essentially operate on 2\naspects of a repository:\n\n    (1) The repository's state.\n    (2) The repository's working tree.\n\nIs there any reason why these commands can't just operate on (1) in a\nbare repository, thereby allowing users to use familiar commands to\nget their work done?\n\nThe \"git checkout\" command in a bare repository should serve to select\non which branch other commands (like \"git reset\") operate, etc.\n\nMichael Witten\n"},{"id":"136664","messageId":"20100312164835.GA2303@progeny.tock","threadId":"22995","inReplyTo":"b4087cc51003120009o7bd99609w996de02b732fbbd9@mail.gmail.com","subject":"Re: [Improvement?] How do you switch branches in a bare repo?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-03-12T16:48:36Z","receivedAt":"2010-03-12T16:48:36Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Michael Witten wrote:\n\n> Commands like \"git checkout\" and \"git reset\" essentially operate on 2\n> aspects of a repository:\n> \n>     (1) The repository's state.\n>     (2) The repository's working tree.\n> \n> Is there any reason why these commands can't just operate on (1) in a\n> bare repository, thereby allowing users to use familiar commands to\n> get their work done?\n\nNot that I can think of.  I’d say go for it.  (I’ll be glad to help in\nany way I can.  Not sure I’ll have much time soon, but I can answer\nquestions, look over patches, and so on.)\n\n> The \"git checkout\" command in a bare repository should serve to select\n> on which branch other commands (like \"git reset\") operate, etc.\n\nMy only worry would be low-level scripts that want to be able to use a\nseparate index or work tree with a bare repository.  Maybe the index\nfile could be in a special \"bare\" state to request the semantics\nyou’re describing.\n\nJonathan\n"},{"id":"136750","messageId":"7v7hpfs8cc.fsf@alter.siamese.dyndns.org","threadId":"22995","inReplyTo":"b4087cc51003120009o7bd99609w996de02b732fbbd9@mail.gmail.com","subject":"Re: [Improvement?] How do you switch branches in a bare repo?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-14T06:52:51Z","receivedAt":"2010-03-14T06:52:51Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Witten <mfwitten@gmail.com> writes:\n\n> The \"git checkout\" command in a bare repository should serve to select\n> on which branch other commands (like \"git reset\") operate, etc.\n\nI am not so sure about the \"should\" part.\n\nThe verb \"checkout\" is to move/copy something that is stored in somewhere\nto some other place, and in the context of git, you are copying out the\ncontents that is stored in the repository (either the index or the tree of\na commit) to the working tree.  It is true that \"git checkout branch\" also\nswitches HEAD while doing so, but that is done primarily so that the\nresult of further working on the checked out files in the working tree\nwill be recorded in that branch, but I tend to see that as secondary.\n\"git checkout file\" and \"git checkout branch file\" do not even touch the\nHEAD.\n\nI am more interested in the reason why you need to switch HEAD in a bare\nrepository to begin with, though.  If it is a one-shot thing, then I don't\nthink it is too unreasonable to ask for people to learn symbolic-ref; if\nsome valid workflow requires to flip the HEAD regularly, on the other\nhand, we might want to give the command to do so a shorter-to-type name\nthan symbolic-ref, and that short name could be \"checkout\".\n"}]}