git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git clone - head not pointing to master

From
Jakub Narebski <jnareb@gmail.com>
Date
Dec 30, 2011, 18:45 UTC
Message-ID
<m34nwhgaop.fsf@localhost.localdomain>
In-Reply-To
<4EFD9F11.5030309@volitionlabs.com>
Vibin Nair <vibin@volitionlabs.com> writes:
Show 18 quoted lines
> Hi,
>   I am a Git beginner. Recently i started working on a codebase (that
> is checked in to a git repository) of our client, who is not very
> aware about how git works.
> The repository has multiple branches such as
> 
> origin/user1
> origin/master
> origin/user2
> 
> Now when i take a clone of this repository : git clone <repo-url>, a
> clone of the repo is created on my machine.
> 
> But when i do a : "git branch" it shows
> 
> user1 *
> 
> which means that the "HEAD" is pointing to the "user1" branch.
Where do you do "git branch"?  In clone or in original repository?
 
Show 9 quoted lines
> The client told me that all the recent code were being merged into the
> "master" branch and hence the "user1" branch has code which is older
> than "master" branch.
> 
> I had 2 queries :
> 
> 1. Is it possible to make the "HEAD" of the remote point to "master"
> instead of "user1", so that other members of my team get the latest
> code when they try to clone the repository.

If you want "origin/HEAD" to point to "origin/master" remote-tracking branch, so that "origin" as a branch means "origin/master", you can use (with modern Git)

  clone$ git remote set-head origin master
or
  clone$ git remote set-head origin
if "master" is now current branch on remote.

If you want to change HEAD i.e. current branch on server (on remote), you can use

  server$ git checkout master
if it is non-bare repository (not recommended setup), or
  server$ git symbolic-ref HEAD refs/heads/master
or equivalently
  server$ git update-ref --no-deref HEAD refs/heads/master
> 2. Is there any way to safely merge "user1" to "master".

You can check if 'user1' can be fast-forwarded to 'master' with

  $ git checkout user1
  $ git merge --ff-only master

This would update 'user1' to 'master', but only if 'master' is just straight advancement of 'user1'.

HTH (Hope That Helps).
-- 
Jakub Narebski
Previous: Konstantin Khomoutov
Message 3 of 3 in “Git clone - head not pointing to master”
  1. Vibin NairDec 30, 2011
  2. Konstantin KhomoutovDec 30, 2011
  3. Jakub NarebskiDec 30, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.