Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git without .git folder -- a remote git-dir

Tags:

git

This question is asked out of curiosity more than for anything practical, but can I effectively have my $GIT_DIR be git://example.com/repo.git/ ? So there would be no .git folder -- every single commit, etc would go through the network overhead.

edit: One potential use case might be for trying to do a simple "export" like svn, but it turns out that question is answered here

like image 918
Alexander Bird Avatar asked Aug 16 '09 09:08

Alexander Bird


People also ask

What happens if you delete the .git directory?

Deleting the . git folder does not delete the other files in that folder which is part of the git repository. However, the folder will no longer be under versioning control.

Do I need .git folder?

A . git folder is required to log every commit history and every other information required for your remote repository, version control, commits etc. These things are saved in different folders which have different meanings. Once the folder is created, open it and see the contents of the folder.

Can I remove the .git folder?

If you're familiar with the terminal window or the DOS prompt, you can easily perform a command line Git repository delete. Just run the rm command with the -f and -r switch to recursively remove the . git folder and all of the files and folders it contains.


2 Answers

$GIT_DIR, introduced in May 2005, is for:

  • specifying both SHA1_FILE_DIRECTORY (was GIT_OBJECT_DIRECTORY, i.e. "$GIT_DIR/objects")
  • GIT_INDEX_FILE ("$GIT_DIR/index")

When GIT_DIR is not defined, it defaults to ".git".

It is meant to be an absolute path or relative path to current working directory, not an http or git absolute path.

Inspired by this post from Junio C. Hamano:

Some commands would not work in the later case.
For instance, "git diff <one-tree>" (representing a way to diff the part of work tree you are currently in with the given tree) would fail.
Note: this is not like "git diff" , which does the same with the index.
With these commands (and others that error out when you run without GIT_DIR outside the work tree), you are really expected to be in the subdirectory you are interested in. .

like image 128
VonC Avatar answered Sep 28 '22 08:09

VonC


I would postulate that if you are asking this question, you may be trying to create a problem to solve.

Just think about why you would need to have a singular git repository people can read and write to directly from their own remote machines, and try add them to the question, because it seems for all the world you're trying to use Git like SVN. And that will end in agony.

For starters, if you don't want to make a complete deep mirror just for creating a patch for upstream, please make note of :

--depth <depth>
Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches. ( git help clone )

like image 25
Kent Fredric Avatar answered Sep 28 '22 09:09

Kent Fredric