To change this current working directory, you can use the "cd" command (where "cd" stands for "change directory").
The . git folder contains all information that is necessary for the project and all information relating commits, remote repository address, etc. It also contains a log that stores the commit history. This log can help you to roll back to the desired version of the code.
All you have to do is load Command Prompt (Load the Start menu, then click "Run", type cmd and hit enter), then you can use Git commands as normal.
From, man git
:
You can do this with the --git-dir
parameter, before passing any commands.
git --git-dir /foo/bar/.git log
(Specifying the .git
directory is necessary.) From the documentation:
--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.
With git 1.8.5 (Q4 2013), you will have another choice, instead of setting --git-dir
.
If you want to execute git log
in folder B
, type:
git -C B log
Just like "
make -C <directory>
", "git -C <directory> ...
" tells Git to go there before doing anything else.
See commit 44e1e4 by Nazri Ramliy:
It takes more keypresses to invoke git command in a different directory without leaving the current directory:
(cd ~/foo && git status)
git --git-dir=~/foo/.git --work-tree=~/foo status
GIT_DIR=~/foo/.git GIT_WORK_TREE=~/foo git status(cd ../..; git grep foo)
for d in d1 d2 d3; do (cd $d && git svn rebase); done
The methods shown above are acceptable for scripting but are too cumbersome for quick command line invocations.
With this new option, the above can be done with fewer keystrokes:
git -C ~/foo status
git -C ../.. grep foo
for d in d1 d2 d3; do git -C $d svn rebase; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With