Full article

As part of a project I'm working on, I've had to clone a lot of repos. Like, several hundred repos. Many of them work together, in small and large projects, some are shared resources for all, and still others are one-offs. It's easy to forget as I'm navigating between directories which repo I'm currently messing with. Which branch am I on? Is it this repo? That repo? A subrepo? A bleepo? Sweepo?

My first thought was to run git status but that only shows the branch and the status of any changed files - not the repo I'm in, or the organization it's associated with. The command I needed was git remote show origin, which shows the URL along with some other info.

> git remote show origin

* remote origin
  Fetch URL: git@github.com:grantwinney/BlogCodeSamples.git
  Push  URL: git@github.com:grantwinney/BlogCodeSamples.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date)

But what if you're after just the URL, without the rest? You can use the git config to query the data you're interested in, in this case remote.origin.url.

> git config --get remote.origin.url


And to get the name of the repo only, run the above output through basename.

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


I'm running in Windows, so I used this fine answer to create a c:\Aliases\whereami.bat file with the following contents in it:

@echo off
git config --get remote.origin.url
git branch

I added it to my path, and now when I'm in a repo I can pound out "whereami" to get my repo name. :)

C:\Users\grant\BlogCodeSamples> whereami

* master

And since you made it this far... 🚀🛸


Grant Winney

I write when I've got something to share - a personal project, a solution to a difficult problem, or just an idea. We learn by doing and sharing. We've all got something to contribute.