Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the Git repository's name in some Git repository?

Tags:

git

repository

People also ask

What is git remote add name URL?

To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. The git remote add command takes two arguments: A unique remote name, for example, “my_awesome_new_remote_repo” A remote URL, which you can find on the Source sub-tab of your Git repo.

Does git repositories have a naming convention?

So the answer to your question is "no, there isn't a naming convention for git repositories".


Well, if, for the repository name you mean the Git root directory name (the one that contains the .git directory) you can run this:

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.


In general, you cannot do this. Git does not care how your git repository is named. For example, you can rename directory containing your repository (one with .git subdirectory), and git will not even notice it - everything will continue to work.

However, if you cloned it, you can use command:

git remote show origin

to display a lot of information about original remote that you cloned your repository from, and it will contain original clone URL.

If, however, you removed link to original remote using git remote rm origin, or if you created that repository using git init, such information is simply impossible to obtain - it does not exist anywhere.


There's no need to contact the repository to get the name, and the folder name won't necessarily reflect the remote name.

I've found this to be the most accurate and efficient way to get the current repository name:

basename -s .git `git config --get remote.origin.url`

This should work as of Git 1.8.1.5. Prior to this, the now deprecated git-repo-config command would have worked (as early as Git 1.7.5).


In git v2.7.0+, a subcommand get-url was introduced to git-remote command.

POSIX shell:

basename $(git remote get-url origin)

PowerShell:

Split-Path -Leaf (git remote get-url origin)