Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git change working directory

Tags:

I want to work with Git repository, but working tree should be remote. For example: if I have my project stored inside of ~/project and project.git stored inside of ~/git/project.git.

What I've changed working tree via config:

worktree=/Users/myuser/project

And I'm able to commit and view diff, but when I've tried to do git stash, I got error:

fatal: /usr/libexec/git-core/git-stash cannot be used without a working tree.

How to store .git directory far from working tree? And why I'm getting this error?

git config --get core.worktree returns correct working directory....

like image 896
ValeriiVasin Avatar asked May 28 '13 12:05

ValeriiVasin


People also ask

How do I change my working directory in Git?

To change this current working directory, you can use the "cd" command (where "cd" stands for "change directory"). For example, to move one directory upwards (into the current folder's parent folder), you can just call: $ cd ..

Does Git checkout change working directory?

Git Checkout File Checking out a file is similar to using git reset with a file path, except it updates the working directory instead of the stage. Unlike the commit-level version of this command, this does not move the HEAD reference, which means that you won't switch branches.

What is the working directory in Git?

The working tree, or working directory, consists of files that you are currently working on. You can think of a working tree as a file system where you can view and modify files. The index, or staging area, is where commits are prepared. The index compares the files in the working tree to the files in the repo.

How do I go to a directory in Git?

Browse to the desired Directory through Commands in Git Bash Open your Git Bash. Type the following command cd <path of the directory> and press enter.


2 Answers

The following seems to work, adjust to your needs:

mkdir git mkdir work git --git-dir git/test --work-tree work/test init mkdir work/test echo -n foo > work/test/foo.txt git --git-dir git/test status git --git-dir git/test add foo.txt git --git-dir git/test commit -m 'commit 1' 

EDIT: Notice that you don't have to specify --work-tree after the repo has been initialized since that value is stored in git/test/config.

You can also cd into work/test and commit from there:

cd work/test echo -n bar > bar.txt git --git-dir ../../git/test status git --git-dir ../../git/test add . git --git-dir ../../git/test commit -m 'commit 2' 

Then use an absolute path for --git-dir or set GIT_DIR.

like image 140
devconsole Avatar answered Sep 17 '22 13:09

devconsole


Correction for --git-dir flag usage:

use:

git --git-dir=git/test/.git ... 

instead of:

git --git-dir git/test ... 
like image 28
ikandars Avatar answered Sep 18 '22 13:09

ikandars