# Feature request for automatic worktree checkout

3 messages from 2016-07-18 to 2016-07-19. Participants: Ehsan Azarnasab, Junio C Hamano, Jacob Keller.
Thread: https://gitlist.dev/t/42872

## Ehsan Azarnasab, 2016-07-18 17:42

Subject: Feature request for automatic worktree checkout
Message-ID: <CADWjqk40KK=AuKqqdpKjkBuUvhQb4k4fMR4bPfdo8JkGRs-Y9w@mail.gmail.com>
URL: https://gitlist.dev/e/CADWjqk40KK%3DAuKqqdpKjkBuUvhQb4k4fMR4bPfdo8JkGRs-Y9w%40mail.gmail.com

```
Currently if I have a branch checked out in a work-tree, git-checkout
will show this error message when checking out that branch:

$ git checkout master
fatal: 'master' is already checked out at '/home/dashesy/development/feature'

It would be very useful to instead of this error just change the
current working directory, so git checkout would become a `cd` command

Ehsan

```

## Junio C Hamano, 2016-07-18 18:33

Subject: Re: Feature request for automatic worktree checkout
Message-ID: <xmqqpoqakd8s.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqpoqakd8s.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <CADWjqk40KK=AuKqqdpKjkBuUvhQb4k4fMR4bPfdo8JkGRs-Y9w@mail.gmail.com>

```
Ehsan Azarnasab <azarnasab@gmail.com> writes:

> Currently if I have a branch checked out in a work-tree, git-checkout
> will show this error message when checking out that branch:
>
> $ git checkout master
> fatal: 'master' is already checked out at '/home/dashesy/development/feature'
>
> It would be very useful to instead of this error just change the
> current working directory, so git checkout would become a `cd` command

That is an understandable thing to want from 10,000ft view, but it
would not be something Git, or any external command that is spawned
by the shell for that matter, can address.  You'd need to teach the
shell to cooperate.

```

## Jacob Keller, 2016-07-19 05:46

Subject: Re: Feature request for automatic worktree checkout
Message-ID: <CA+P7+xoeO43A+BdkdzeMpuKh=B7Ma+JVq3WR5bsX8XGYxPdmxg@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BP7%2BxoeO43A%2BBdkdzeMpuKh%3DB7Ma%2BJVq3WR5bsX8XGYxPdmxg%40mail.gmail.com
In-Reply-To: <xmqqpoqakd8s.fsf@gitster.mtv.corp.google.com>

```
On Mon, Jul 18, 2016 at 11:33 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Ehsan Azarnasab <azarnasab@gmail.com> writes:
>
>> Currently if I have a branch checked out in a work-tree, git-checkout
>> will show this error message when checking out that branch:
>>
>> $ git checkout master
>> fatal: 'master' is already checked out at '/home/dashesy/development/feature'
>>
>> It would be very useful to instead of this error just change the
>> current working directory, so git checkout would become a `cd` command
>
> That is an understandable thing to want from 10,000ft view, but it
> would not be something Git, or any external command that is spawned
> by the shell for that matter, can address.  You'd need to teach the
> shell to cooperate.
> --

You could implement this for yourself as a shell function sort of, by
wrapping git, but it's a bit crazy, something like:

function git() {
  # check if first argument is checkout, otherwise exec git
  # check second argument, and parse git-worktree to determine if it
is checked out
  # if so, just cd into the directory
  # else exec git normally.
}

I'll leave actual implementations to the user. Note at least for BASH,
you need to actually do this as a function alias.

Thanks,
Jake

```
