Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working on git repo without cd into directory

Tags:

git

How would I run git commands on a repo when I have not cd'd into that directory?

I.e. I want to run git branch /repos/myrepo.git

like image 940
Mike007 Avatar asked Aug 14 '11 23:08

Mike007


People also ask

How do I copy a repository to a directory?

To clone git repository into a specific folder, you can use -C <path> parameter, e.g. Although it'll still create a whatever folder on top of it, so to clone the content of the repository into current directory, use the following syntax: cd /httpdocs git clone [email protected]:whatever .


2 Answers

Starting with git 1.8.5, use the -C option.

git -C "/Users/michael/Development/Projects/opensource/dvsc-backup" status 

Otherwise, you have to specify --work-tree as well as --git-dir

git --work-tree="/Users/michael/Development/Projects/opensource/dvsc-backup" --git-dir="/Users/michael/Development/Projects/opensource/dvsc-backup/.git" status 
like image 154
Christian Long Avatar answered Oct 03 '22 12:10

Christian Long


--git-dir=<path>

Set the path to the repository. This can also be controlled by setting the GIT_DIR environment variable. It can be an absolute path or relative path to current working directory.

http://www.kernel.org/pub/software/scm/git/docs/git.html

Note that <path> above means the path to the actual git directory (project_dir/.git) not just the project directory (project_dir).

like image 23
Tyler Avatar answered Oct 03 '22 12:10

Tyler