Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fatal: Not a git repository: '.git' error

Tags:

git

git-bash

hook

I have created a pre-commit hook which takes the database dump and saves it in a file under my application/folder which is also in the git repo, after saving it I add the file to commit list . Following is the code in my pre-commit file

    D:/xampp/mysql/bin/mysqldump -u root -pxyz --skip-extended-insert [database] > D:/xampp/htdocs/app/application/[database].sql

cd D:/xampp/htdocs/app/application
git add [database].sql

I tried to run the pre-commit code directly through command prompt it works without any error but when I try to commit the code through git bash I get this error

fatal: Not a git repository: '.git' 

I am assuming its because of the git command used in the pre-commit file, can anyone tell me whats wrong in this file and how I should amend it

like image 515
Anand Joshi Avatar asked Aug 11 '12 13:08

Anand Joshi


People also ask

How do you fix fatal origin does not appear to be a git repository?

Note: The “fatal: 'origin' does not appear to be a git repository” error occurs when you try to push code to a remote Git repository without telling Git the exact location of the remote repository. To solve this error, use the git remote add command to add a remote to your project.

What does fatal not a git repository mean?

The cause of this error message is running a Git command outside of a directory in which a Git folder is initialized. For instance, if you try to run “git commit” in a non-Git folder, you see an error. Git cannot run unless you view a folder configured with Git.


2 Answers

In doubt, in your hook, set up explicitly git-dir and work-tree parameters:

git --git-dir .git --work-tree . add ...

You can even put the full path to be extra-sure:

git --git-dir D:/xampp/htdocs/app/application/.git --work-tree D:/xampp/htdocs/app/application/. add ...

That way, you rule out any environment issue with those git-dir or work-tree stuck into another path which isn't the one of the repo your are cd'ing into.
See "Calling 'git pull' from a git post-update hook" for an example of that problem.

like image 122
VonC Avatar answered Oct 04 '22 15:10

VonC


i had the exact same issue like you and found this solution:

instead of doing

cd D:/xampp/htdocs/app/application
git add [database].sql

i simply did

git add D:/xampp/htdocs/app/application/[database].sql

that way i didn't irritate git by cd-ing into another folder :)

like image 25
nerdess Avatar answered Oct 04 '22 17:10

nerdess