git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Git clone - head not pointing to master
@ 2011-12-30 11:22 Vibin Nair
  2011-12-30 12:40 ` Konstantin Khomoutov
  2011-12-30 18:45 ` Jakub Narebski
  0 siblings, 2 replies; 3+ messages in thread
From: Vibin Nair @ 2011-12-30 11:22 UTC (permalink / raw)
  To: git

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.

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.
2. Is there any way to safely merge "user1" to "master".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Git clone - head not pointing to master
  2011-12-30 11:22 Git clone - head not pointing to master Vibin Nair
@ 2011-12-30 12:40 ` Konstantin Khomoutov
  2011-12-30 18:45 ` Jakub Narebski
  1 sibling, 0 replies; 3+ messages in thread
From: Konstantin Khomoutov @ 2011-12-30 12:40 UTC (permalink / raw)
  To: Vibin Nair; +Cc: git

On Fri, 30 Dec 2011 16:52:57 +0530
Vibin Nair <vibin@volitionlabs.com> wrote:

>   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.
> 
> 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.
`git clone` checks out the branch which the HEAD ref in the remote repo
points to.  You can use `git symbolic-ref` to retarget HEAD if it's a
bare repository.  If the repository is non-bare HEAD tracks what's
checked out, so it can be changed by doing `git checkout`.
Note that you can pass the "-b <branch>" command-line option to `git
clone` to make it create a local tracking branch and check it out for
an arbitrary remote branch <branch>.

> 2. Is there any way to safely merge "user1" to "master".
This question has little sense because it heavily depends on what you
mean by "safely".  The correct way to state a question like this is to
think whether merging user1 to master has sense from the project's
development standpoint.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Git clone - head not pointing to master
  2011-12-30 11:22 Git clone - head not pointing to master Vibin Nair
  2011-12-30 12:40 ` Konstantin Khomoutov
@ 2011-12-30 18:45 ` Jakub Narebski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Narebski @ 2011-12-30 18:45 UTC (permalink / raw)
  To: Vibin Nair; +Cc: git

Vibin Nair <vibin@volitionlabs.com> writes:

> 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?
 
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-12-30 18:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-30 11:22 Git clone - head not pointing to master Vibin Nair
2011-12-30 12:40 ` Konstantin Khomoutov
2011-12-30 18:45 ` Jakub Narebski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).