threads / discuss / 42872

Feature request for automatic worktree checkout

Subject: Feature request for automatic worktree checkout

## tl;dr

3 messages between Jul 18, 2016 and Jul 19, 2016.

replies: 2people: 3as markdown or json

Ehsan Azarnasab· Jul 18, 2016, 17:42 UTC · lore

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· Jul 18, 2016, 18:33 UTC · re: Ehsan Azarnasab · lore

Re: Feature request for automatic worktree checkout

Ehsan Azarnasab <azarnasab@gmail.com> writes:
Show 8 quoted lines
> 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· Jul 19, 2016, 05:46 UTC · re: Junio C Hamano · lore

Re: Feature request for automatic worktree checkout

On Mon, Jul 18, 2016 at 11:33 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 16 quoted lines
> 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

← back to recent threads