-
Notifications
You must be signed in to change notification settings - Fork 7
Find a git repo on your system by its remote URL
If you cloned a repo but can't find it on your system, surely you can figure out where it is?
- list all git repos by searching for directories called .git
- better yet, make an index of all such directories
- use
git remote show originto show the repo source (i.e. GitHub URL: user/org and repo name)
-
findafileis a function:find / -iname "$@" 2> /dev/null -
findafile .gitlists all git repos -
findafile .git | head -4returns a list (to figure it out I'm just getting a few withhead)/gits/getpaperstmp/.git /gits/grc-issues-backup/.git /gits/euler/.git /gits/websiteresources/.git -
git-configis the tool to query a repo's.git/configfile, which has a line with the URL in, e.g. for this repository wiki (yes, you can clone a GitHub wiki!)[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = git@github.com:lmmx/devnotes.wiki.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master- get the parameter by calling
git config --get remote.origin.urlif inside the directory above.git/, - or point it at the directory using the
--git-dirflag:git --git-dir=devnotes.wiki/.git config --get remote.origin.url
- get the parameter by calling
-
So... to do this for a list, such as the one I took the
headof above, apply a call toxargs,findafile .git | head -4 | xargs -I {} git --git-dir={} config --get remote.origin.url
-
an improvement would be to print out say, tab-separated columns of the directory and the remote URL, but I can't quite see how to do this
- if you rename the
{}argument by placing a variable name to use after it and replacing the--git-dirflag parameter with said word, the word isn't parsed (e.g. declaring 'gitdir' as the variable reports "xargs: gitdir: No such file or directory")
- if you rename the
-
since you can't (?) do that, it's fine to just run the call twice (kinda defeats the purpose of calling
xargsbut whatever - for the purpose I'm writing this for, I just want to grep to see if a certain repo URL exists, i.e. if I have it on my computer, so it'll do)
Fin!
- making an index saves running this command which is kind of slow
- see https://github.com/spin-arb/in