{"thread":{"id":"29269","subject":"Git clone - head not pointing to master","startedAt":"2011-12-30T11:22:57Z","lastAt":"2011-12-30T18:45:53Z","messageCount":3,"participants":["Vibin Nair","Konstantin Khomoutov","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"181800","messageId":"4EFD9F11.5030309@volitionlabs.com","threadId":"29269","inReplyTo":null,"subject":"Git clone - head not pointing to master","fromName":"Vibin Nair","fromEmail":"vibin@volitionlabs.com","sentAt":"2011-12-30T11:22:57Z","receivedAt":"2011-12-30T11:22:57Z","isPatch":false,"sender":{"key":"vibin@volitionlabs.com","avatar":null},"body":"Hi,\n  I am a Git beginner. Recently i started working on a codebase (that is \nchecked in to a git repository) of our client, who is not very aware \nabout how git works.\nThe repository has multiple branches such as\n\norigin/user1\norigin/master\norigin/user2\n\nNow when i take a clone of this repository : git clone <repo-url>, a \nclone of the repo is created on my machine.\n\nBut when i do a : \"git branch\" it shows\n\nuser1 *\n\nwhich means that the \"head\" is pointing to the \"user1\" branch.\n\nThe client told me that all the recent code were being merged into the \n\"master\" branch and hence the \"user1\" branch has code which is older \nthan \"master\" branch.\n\nI had 2 queries :\n\n1. Is it possible to make the \"head\" of the remote point to \"master\" \ninstead of \"user1\", so that other members of my team get the latest code \nwhen they try to clone the repository.\n2. Is there any way to safely merge \"user1\" to \"master\".\n"},{"id":"181802","messageId":"20111230164058.f127bf2d.kostix@domain007.com","threadId":"29269","inReplyTo":"4EFD9F11.5030309@volitionlabs.com","subject":"Re: Git clone - head not pointing to master","fromName":"Konstantin Khomoutov","fromEmail":"flatworm@users.sourceforge.net","sentAt":"2011-12-30T12:40:58Z","receivedAt":"2011-12-30T12:40:58Z","isPatch":false,"sender":{"key":"flatworm@users.sourceforge.net","avatar":null},"body":"On Fri, 30 Dec 2011 16:52:57 +0530\nVibin Nair <vibin@volitionlabs.com> wrote:\n\n>   I am a Git beginner. Recently i started working on a codebase (that\n> is checked in to a git repository) of our client, who is not very\n> aware about how git works.\n> The repository has multiple branches such as\n> \n> origin/user1\n> origin/master\n> origin/user2\n> \n> Now when i take a clone of this repository : git clone <repo-url>, a \n> clone of the repo is created on my machine.\n> \n> But when i do a : \"git branch\" it shows\n> \n> user1 *\n> \n> which means that the \"head\" is pointing to the \"user1\" branch.\n> \n> The client told me that all the recent code were being merged into\n> the \"master\" branch and hence the \"user1\" branch has code which is\n> older than \"master\" branch.\n> \n> I had 2 queries :\n> \n> 1. Is it possible to make the \"head\" of the remote point to \"master\" \n> instead of \"user1\", so that other members of my team get the latest\n> code when they try to clone the repository.\n`git clone` checks out the branch which the HEAD ref in the remote repo\npoints to.  You can use `git symbolic-ref` to retarget HEAD if it's a\nbare repository.  If the repository is non-bare HEAD tracks what's\nchecked out, so it can be changed by doing `git checkout`.\nNote that you can pass the \"-b <branch>\" command-line option to `git\nclone` to make it create a local tracking branch and check it out for\nan arbitrary remote branch <branch>.\n\n> 2. Is there any way to safely merge \"user1\" to \"master\".\nThis question has little sense because it heavily depends on what you\nmean by \"safely\".  The correct way to state a question like this is to\nthink whether merging user1 to master has sense from the project's\ndevelopment standpoint.\n"},{"id":"181809","messageId":"m34nwhgaop.fsf@localhost.localdomain","threadId":"29269","inReplyTo":"4EFD9F11.5030309@volitionlabs.com","subject":"Re: Git clone - head not pointing to master","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2011-12-30T18:45:53Z","receivedAt":"2011-12-30T18:45:53Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Vibin Nair <vibin@volitionlabs.com> writes:\n\n> Hi,\n>   I am a Git beginner. Recently i started working on a codebase (that\n> is checked in to a git repository) of our client, who is not very\n> aware about how git works.\n> The repository has multiple branches such as\n> \n> origin/user1\n> origin/master\n> origin/user2\n> \n> Now when i take a clone of this repository : git clone <repo-url>, a\n> clone of the repo is created on my machine.\n> \n> But when i do a : \"git branch\" it shows\n> \n> user1 *\n> \n> which means that the \"HEAD\" is pointing to the \"user1\" branch.\n\nWhere do you do \"git branch\"?  In clone or in original repository?\n \n> The client told me that all the recent code were being merged into the\n> \"master\" branch and hence the \"user1\" branch has code which is older\n> than \"master\" branch.\n> \n> I had 2 queries :\n> \n> 1. Is it possible to make the \"HEAD\" of the remote point to \"master\"\n> instead of \"user1\", so that other members of my team get the latest\n> code when they try to clone the repository.\n\nIf you want \"origin/HEAD\" to point to \"origin/master\" remote-tracking\nbranch, so that \"origin\" as a branch means \"origin/master\", you can\nuse (with modern Git)\n\n  clone$ git remote set-head origin master\n\nor\n\n  clone$ git remote set-head origin\n\nif \"master\" is now current branch on remote.\n\n\nIf you want to change HEAD i.e. current branch on server (on remote),\nyou can use\n\n  server$ git checkout master\n\nif it is non-bare repository (not recommended setup), or\n\n  server$ git symbolic-ref HEAD refs/heads/master\n\nor equivalently\n\n  server$ git update-ref --no-deref HEAD refs/heads/master\n\n\n> 2. Is there any way to safely merge \"user1\" to \"master\".\n\nYou can check if 'user1' can be fast-forwarded to 'master'\nwith\n\n  $ git checkout user1\n  $ git merge --ff-only master\n\nThis would update 'user1' to 'master', but only if 'master' is just\nstraight advancement of 'user1'.\n\nHTH (Hope That Helps).\n-- \nJakub Narebski\n"}]}