When you are working in some Git directory, how can you get the Git repository name in some Git repository? Are there any Git commands?
# I did check out bar repository and working in somewhere
# under bar directory at this moment such as below.
$ git clone git://github.com/foo/bar.git
$ cd bar/baz/qux/quux/corge/grault # and I am working in here!
$ git xxx # <- ???
bar
In Git, there's no concept of a repository name. The repository itself is kept under a directory in the file system (the one that contains the .git
directory) and you can get the name of that directory with the following command:
basename `git rev-parse --show-toplevel`
The git rev-parse --show-toplevel
part gives you the path to that directory and basename
strips the first part of the path.
Another common sense interpretation to a "Git's repository name" is the name used to identify the repository in a Git hosting service (such as GitHub or GitLab). That name can be obtained by looking at the remote information, and a few different ways to achieve that are documented in other answers to this question.