Alex Rivera | Logout

git checkout branch from outside

Asked 2011-05-20T14:38:35.523
41

Problem: I need somehow to checkout an existing branch of a project that is already cloned locally on my file system without being in that particular folder of this project.

Solution: I'm trying to do the following:

  1. git clone 'github-project-url' 'file-system-folder'
  2. git checkout 'existing-branch' 'file-system-folder'

I do realize that second step is not quite right, but I also am trying to avoid to cd 'file-system-folder'.

Edit
Report

1 Answer

79

You can use --git-dir to specify the .git directory to use as the repository, and --work-tree to specify the working tree to to the checkout in. See the git man page for details.

git --git-dir=file-system-folder/.git --work-tree=file-system-folder checkout existing-branch
answered 2011-05-20T14:46:51.667

Your Answer