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
Also I just find that there is some repo information inside .git
directory. So you can just watch FETCH_HEAD
file in terminal to see repo's name:
Example:
cd your_project_folder/.git
more FETCH_HEAD
Output:
672e38391557a192ab23a632d160ef37449c56ac https://bitbucket.org/fonjeekay/some_repo
And https://bitbucket.org/somebituser/some_repo.git
is the name of your repository
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.
I think this is a better way to unambiguously identify a clone of a repository.
git config --get remote.origin.url
and checking to make sure that the origin matches ssh://your/repo
.
You can use: git remote -v
Documentation: https://git-scm.com/docs/git-remote
Manage the set of repositories ("remotes") whose branches you track. -v --verbose Be a little more verbose and show remote url after name. NOTE: This must be placed between remote and subcommand.
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).
If you want the whole GitHub repository name ('full name') - user/repository, and you want to do it in with Ruby...
git remote show origin -n | ruby -ne 'puts /^\s*Fetch.*:(.*).git/.match($_)[1] rescue nil'