4

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.

Jatin Ganhotra
  • 6,825
  • 6
  • 48
  • 71

4 Answers4

9

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.

JosefAssad
  • 4,018
  • 28
  • 37
  • I didn't add the binaries to `$PATH`, instead I made aliases in bash config files. Never thought that would make a difference, until now. Thanks a lot. – Jatin Ganhotra Aug 15 '12 at 15:16
  • As now my git binary path is not in $PATH, gitk can't find git and thus this error comes out. So, once I add the binaries path, the error would go right. – Jatin Ganhotra Aug 15 '12 at 15:17
  • I have to stress again, the right answer is to use the package manager. But if you insist not to then yes, making sure that the gitk program can find the git executable is the solution. Whether this will lead to gitk running as expected I cannot say, however, since I don't know what other things there might be the matter with your git installation. :) Use the package manager, world peace depends upon it. :) – JosefAssad Aug 15 '12 at 15:52
  • Do you recommend using package-manager in a centralized environment. I think after some time, the common locations where a package-manager would copy the files would become too packed and cluttered. What are your thoughts on this? – Jatin Ganhotra Aug 15 '12 at 16:48
  • I don't know what you mean with the expression "centralised environment" but it is ALWAYS a better idea to use the package manager than to roll software by hand. The presence of many executables in one location such as /usr/bin is not in any way a problem. – JosefAssad Aug 15 '12 at 16:51
  • I mean a central area which is used by every developer in a team/organisation. IMO, this discussion would be off-topic in regards to this question. Will try the solution that you suggested & keep you posted. BTW, Thanks a lot :) – Jatin Ganhotra Aug 15 '12 at 17:40
  • Thank you for making an effort to keep on the topic of this SO question. :) To point you in the right direction, look at the accepted answer here: http://stackoverflow.com/questions/3779274/how-can-git-be-installed-on-centos-5-5 – JosefAssad Aug 16 '12 at 06:49
  • Thanks for all the help. The problem was with the $PATH. Fixing the $PATH made gitk work smoothly. I am accepting your answer, but would like to edit it, since you have stressed so much on using a package-manager, someone like me who wants a hand-rolled git won't benefit from this question. – Jatin Ganhotra Aug 22 '12 at 09:26
  • Well I use a package manager, and my exe is in my path, and I'm still getting this. I suspect it has something to do with the many `warning: encountered old-style '///server/share/.gitignore' that should be '%(prefix)///server/share/.gitignore` (and for `.gitattributes`) errors I've been getting for weeks now, but aren't explained or documented, and can't find any mention of using Google. – brianary Dec 20 '21 at 17:49
  • Searching the entire `git` and `gitster` users on GitHub for both `old-style` and `prefix` also don't seem to provide any help. – brianary Dec 20 '21 at 17:53
1

Make sure that /tmp is writable.

This was the problem when I got this error.

not-a-user
  • 4,088
  • 3
  • 21
  • 37
-1

I can see this same problem when /tmp filesystem is full.

David
  • 39
  • 3
-2

In your Git repository simply run:

$ git-init 

gitk will now see your git directory.

For more check out the git-init man page.

Jules0707
  • 605
  • 7
  • 3
  • If this actually fixes the problem, then the dir wasn't a git repo to begin with. Clearly, the person asking actually had a repo there. Worse, with old versions of git, `git init` provides no warning. This means that `git init` will **wipe out all history in the local copy of the repo**. _Someone_ needs to read that man page, and I daresay it isn't the person asking. – Mark Jan 12 '17 at 16:50