Question

When I run gitk, a Tk window pops-up saying that "It cannot find a GIT repository here".
What am I missing? These are the steps I followed. Forgive me if I missed something stupid.

[~/TEMP]$ ls
[~/TEMP]$ git init abc
Initialized empty Git repository in /*******/home/jganhotra/TEMP/abc/.git/

Added a file

[~/TEMP]$ cd abc/
[~/TEMP]$ ls -la
total 16
drwxr-x---  3 jganhotra eng 4096 Aug 15 16:05 ./
drwxr-x---  3 jganhotra eng 4096 Aug 15 16:04 ../
drwxr-x---  8 jganhotra eng 4096 Aug 15 16:05 .git/
[abc]$ touch a.txt
[abc]$ gvim a.txt 
[abc]$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       a.txt
nothing added to commit but untracked files present (use "git add" to track)
[abc]$ git add .
[abc]$ git commit -m "Added file"
[master (root-commit) 1ff1051] Added file
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt

Made the commit

[abc]$ git status
# On branch master
nothing to commit (working directory clean)
[abc]$ git log
commit 1ff1051370dfb69a0e85a60f322da7389366db8b
Author: Jatin Kumar Ganhotra <jganhotra@******.com>
Date:   Mon Aug 13 19:10:38 2012 +0530

    Added file

[abc]$ gitk
[abc]$ which gitk
gitk:    aliased to /*******/tools/install/git-tools/git-1.7.11.2/bin/gitk

[abc]$ ls -la /******/tools/install/git-tools/git-1.7.11.2/bin/gitk
-rwxr-x---  1 devadmin eng 329597 Jul 17 17:43 /*******/tools/install/git-tools/git-1.7.11.2/bin/gitk

This should have worked. What have I missed? I believe there is some dependency left.

Was it helpful?

Solution

Well. First off, the only actual correct answer here is, use your package manager and your problem will go away.

But I'll explain why I'm saying that. your package manager will drop the git files in locations which are in your $PATH for all your login and shell sessions.

I see you have git installed manually compiled from source in a creatively composed path titled /******/tools/install/git-tools/git-1.7.11.2/. I think what is happening is this: you have either added the git binaries to your $PATH only in this login/shell session, or you have aliased them in your bash config files.

That would cause the error you're seeing. Reading the source of gitk, you can see that the error happens here:

if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
show_error {} . [mc "Cannot find a git repository here."]
exit 1
}

So, gitk uses the git binary to check if there's a git repo there. But gitk can't find the git binary because it doesn't access your shell aliases or any temporary changes you might have made to $PATH somewhere in some ephemeral login/shell session.

So use your package manager. :) Or fix your paths, if you insist on having a hand-rolled git.

OTHER TIPS

Make sure that /tmp is writable.

This was the problem when I got this error.

In your Git repository simply run:

$ git-init 

gitk will now see your git directory.

For more check out the git-init man page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top