Question

Imagine this folder structure:

foo/
  bar/.git # branch=master
  baz/.git # branch=test

Now imagine that my current path is foo/bar, but without switching directories, I would like to write a command that tells baz to checkout the branch master (already stored locally). In an ideal world, this would look something like:

[foo/bar]$ git --use-path=../baz checkout master
[foo/bar]$

I am trying to avoid doing:

[foo/bar]$ cd ../baz
[foo/baz]$ git checkout master
[foo/baz]$ cd ../bar
[foo/bar]$

I would also prefer something built into git, and would like to avoid concatenating commands.

Was it helpful?

Solution

You can use the -C switch for that. From the manual:

-C <path>

Run as if git was started in <path> instead of the current working directory. When multiple -C options are given, each subsequent non-absolute -C <path> is interpreted relative to the preceding -C <path>.

This feature was added in Git 1.8.5.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top