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?
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.
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.
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 ..
The git clone command creates a copy of an existing repository to a working directory on your local computer.
Try this:
git rev-parse --show-toplevel
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With