# [Q] Changing the current branch (HEAD) in a bare repository - how?

3 messages from 2008-06-06 to 2008-06-06. Participants: Brian Foster, Johannes Schindelin, Jakub Narebski.
Thread: https://gitlist.dev/t/13832

## Brian Foster, 2008-06-06 15:43

Subject: [Q] Changing the current branch (HEAD) in a bare repository - how?
Message-ID: <a537dd660806060843p4e92932x4e0f5464c5fd1da1@mail.gmail.com>
URL: https://gitlist.dev/e/a537dd660806060843p4e92932x4e0f5464c5fd1da1%40mail.gmail.com

```
 Using git 1.5.2.5 (Kubuntu 7.10) and a bare repository,
 I started with (the commands and output below are typed
 in by hand, mostly from memory):

    $ git branch -a
    * master
      foo
    $

 and then changed the branch names:

    $ git branch -m master old-master
    $ git branch -m foo master

 and got this:

    $ git branch -a
      master
    * old-master
    $

 Now, how do I change the current branch to the (new)
 `master'?  A `checkout' fails:

    $ git checkout master
    fatal: /usr/bin/git-checkout cannot be used without a working tree.
    $

 I (ultimately) hand-edited `HEAD' (apparently successfully),
 but am wondering what I should have done or may have missed?

 I didn't spot anything in TFM, albeit I could have easily overlooked
 or misunderstood something.

cheers!
	-blf-

-- 
"How many surrealists does it take to   | Brian Foster
 change a lightbulb? Three. One calms   | somewhere in south of France
 the warthog, and two fill the bathtub  | Stop E$$o (ExxonMobil)!
 with brightly-coloured machine tools." | http://www.stopesso.com

```

## Johannes Schindelin, 2008-06-06 15:47

Subject: Re: [Q] Changing the current branch (HEAD) in a bare repository - how?
Message-ID: <alpine.DEB.1.00.0806061646280.1783@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0806061646280.1783%40racer
In-Reply-To: <a537dd660806060843p4e92932x4e0f5464c5fd1da1@mail.gmail.com>

```
Hi,

On Fri, 6 Jun 2008, Brian Foster wrote:

>  Using git 1.5.2.5 (Kubuntu 7.10) and a bare repository,
>  I started with (the commands and output below are typed
>  in by hand, mostly from memory):
> 
>     $ git branch -a
>     * master
>       foo
>     $
> 
>  and then changed the branch names:
> 
>     $ git branch -m master old-master
>     $ git branch -m foo master
> 
>  and got this:
> 
>     $ git branch -a
>       master
>     * old-master
>     $
> 
>  Now, how do I change the current branch to the (new)
>  `master'?

vi HEAD

Ciao,
Dscho

```

## Jakub Narebski, 2008-06-06 16:03

Subject: Re: [Q] Changing the current branch (HEAD) in a bare repository - how?
Message-ID: <m3k5h2y2iz.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3k5h2y2iz.fsf%40localhost.localdomain
In-Reply-To: <a537dd660806060843p4e92932x4e0f5464c5fd1da1@mail.gmail.com>

```
"Brian Foster" <brian.foster@innova-card.com> writes:

>  Using git 1.5.2.5 (Kubuntu 7.10) and a bare repository,
>  I started with (the commands and output below are typed
>  in by hand, mostly from memory):
> 
>     $ git branch -a
>     * master
>       foo
>     $
> 
>  and then changed the branch names:
> 
>     $ git branch -m master old-master
>     $ git branch -m foo master
> 
>  and got this:
> 
>     $ git branch -a
>       master
>     * old-master
>     $
> 
>  Now, how do I change the current branch to the (new)
>  `master'?  A `checkout' fails:
> 
>     $ git checkout master
>     fatal: /usr/bin/git-checkout cannot be used without a working tree.
>     $

In a bare repository it doesn't matter (almost) which branch is
current one (there is no _checked out_ branch, so it only matters as a
default checked out branch for clone, IIRC).
 
>  I (ultimately) hand-edited `HEAD' (apparently successfully),
>  but am wondering what I should have done or may have missed?

You have to rely on plumbing:

  $ git symbolic-ref HEAD master

(see documentation for details).
-- 
Jakub Narebski
Poland
ShadeHawk on #git

```
