Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out what Git thinks the top-level working directory is? [duplicate]

Tags:

Possible Duplicate:
Is there a way to get to the git root directory in one command?

Sometimes, I'm confused with git thinking that I'm inside a Git working dir, but it's not obvious to me what the top-level working directory (containing .git/) is. (Probably, that repo was created by a mistake.)

So, how do I find out the top-level Git repo directory if I'm somewhere inside the subdirectories? How do I ask git to print what it thinks the current top-level working directory is?

like image 470
imz -- Ivan Zakharyaschev Avatar asked Jul 19 '11 13:07

imz -- Ivan Zakharyaschev


People also ask

How does Git handle duplicate files?

To be efficient, if files have not changed, Git doesn't store the file again, just a link to the previous identical file it has already stored. Git thinks about its data more like a stream of snapshots.

What is my current working directory Git?

git directory is a configuration file for git. Use the terminal to display the . git directory with the command ls -a . The ls command lists the current directory contents and by default will not show hidden files.

How do I change the 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 clone creates a working directory?

The git clone command creates a copy of an existing repository to a working directory on your local computer.


2 Answers

Try this:

git rev-parse --show-toplevel 
like image 100
Graham Borland Avatar answered Sep 20 '22 23:09

Graham Borland


I've written a simple script (git-find-git-dirs in my "git-shortcuts" collection) to make such queries to Git handy:

#!/bin/bash  # find-git-dirs -- A simple script to "find" (i.e., "print") the GIT_DIR, as assumed by Git. (Useful if you are in a subdir, and you are not sure about the top-level repo dir.)  SUBDIRECTORY_OK=yes . "$(git --exec-path)/git-sh-setup"  echo "GIT_DIR=$GIT_DIR" 

and put it to ~/bin/; now I can do my simple query like this:

$ git find-git-dirs GIT_DIR=/home/imz/.git GIT_WORK_TREE= $  

The only thing I lack from the initial question is the printing of the top-level working dir, now it just prints the path to the internal git repo dir...

like image 44
imz -- Ivan Zakharyaschev Avatar answered Sep 18 '22 23:09

imz -- Ivan Zakharyaschev