| created | "2025-12-16T00:00:00.000Z" |
| modified | "2026-04-25T00:00:00.000Z" |
| reviewed | "2026-04-25T00:00:00.000Z" |
| name | git-repo-detection |
| description | Detect GitHub repo owner/name from git remotes. Use when needing the owner/repo identifier for GitHub CLI or API calls, especially across multiple repos. |
| user-invocable | false |
| allowed-tools | Bash, Read, Grep |
Git Repository Detection
When to Use This Skill
| Use this skill when... | Use the alternative when... |
|---|
Extracting owner/repo from a git remote (HTTPS or SSH URL) for gh calls | Use gh-cli-agentic once you already have the owner/repo identifier |
| Handling GitHub Enterprise host URLs alongside github.com | Use git-fork-workflow when the question is fork vs upstream identification |
Resolving the repo identifier to pass with gh -R to avoid remote-required errors | Use git-cli-agentic for raw git remote -v parsing if you need URL details |
| Detecting which repo a script is running inside before issuing API calls | Use git-coworker-check to detect concurrent agents in the same checkout |
Expert knowledge for detecting and extracting GitHub repository information from git remotes, including repository name, owner, and full identifiers.
Core Expertise
Repository Identification
- Extract owner and repository name from git remotes
- Parse GitHub URLs (HTTPS and SSH)
- Handle GitHub Enterprise URLs
- Format as
owner/repo for CLI/API usage
URL Parsing
- Parse HTTPS URLs:
https://github.com/owner/repo.git
- Parse SSH URLs:
git@github.com:owner/repo.git
- Handle custom domains:
https://github.enterprise.com/owner/repo.git
- Clean
.git suffix and extra paths
Essential Commands
Get Remote URLs
git remote -v
git remote get-url origin
git remote get-url upstream
git remote show origin
Extract Repository Name
git remote get-url origin | sed 's/.*\/\([^/]*\)\.git/\1/'
git remote get-url origin | sed 's/.*:\([^/]*\/[^/]*\)\.git/\1/' | cut -d'/' -f2
git remote get-url origin | sed 's/.*[:/]\([^/]*\/[^/]*\)\.git/\1/'
basename $(git remote get-url origin) .git
Extract Owner
git remote get-url origin | sed 's/.*[:/]\([^/]*\)\/[^/]*\.git/\1/'
git remote get-url origin | awk -F '[:/]' '{print $(NF-1)}'
Get Full Identifier (owner/repo)
git remote get-url origin | sed 's/.*[:/]\([^/]*\/[^/]*\)\.git/\1/'
REPO=$(git remote get-url origin 2>/dev/null | sed 's/.*[:/]\([^/]*\/[^/]*\)\.git/\1/')
echo "${REPO:-Unknown}"
REPO_FULL=$(git remote get-url origin | sed 's/.*[:/]\([^/]*\/[^/]*\)\.git/\1/')
echo "Repository: $REPO_FULL"
URL Format Examples
HTTPS URLs
https://github.com/owner/repo.git
https://github.com/owner/repo
https://github.company.com/owner/repo.git
SSH URLs
git@github.com:owner/repo.git
ssh://git@github.com:443/owner/repo.git
git@github.company.com:owner/repo.git
Parsing Patterns
Universal Parser (HTTPS or SSH)
parse_repo() {
local url="$1"
url="${url%.git}"
if [[ "$url" =~ github\.com[:/]([^/]+/[^/]+) ]]; then
echo "${BASH_REMATCH[1]}"
elif [[ "$url" =~ :([^/]+/[^/]+)$ ]]; then
echo "${BASH_REMATCH[1]}"
fi
}
REPO=$(parse_repo "$(git remote get-url origin)")
echo "$REPO"
Robust Extraction with sed
git remote get-url origin \
| sed -E 's#.*github\.com[:/]##; s#\.git$##'
Using awk
git remote get-url origin \
| awk -F'[/:]' '{print $(NF-1)"/"$NF}' \
| sed 's/\.git$//'
Real-World Usage
With GitHub CLI
REPO=$(git remote get-url origin | sed 's/.*[:/]\([^/]*\/[^/]*\)\.git/\1/')
gh repo view "$REPO"
gh issue list --repo "$REPO"
gh pr list --repo "$REPO"
gh repo view
For API usage, multiple remotes, scripts, aliases, and integration examples, see REFERENCE.md.
Edge Cases
| Case | Check |
|---|
| No remote | git remote get-url origin &>/dev/null |
| Non-GitHub | git remote get-url origin | grep -q github.com |
| Multiple remotes | Use git remote get-url upstream for fork source |
| Submodule | git -C "$(git rev-parse --show-toplevel)" remote get-url origin |
Quick Reference
| Purpose | Command |
|---|
| Full identifier (owner/repo) | git remote get-url origin | sed 's/.*[:/]\([^/]*\/[^/]*\)\.git/\1/' |
| Owner only | git remote get-url origin | sed 's/.*[:/]\([^/]*\)\/[^/]*\.git/\1/' |
| Name only | basename $(git remote get-url origin) .git |
| Is GitHub? | git remote get-url origin | grep -q github.com |
| Validate in git repo | git rev-parse --git-dir &>/dev/null |
| List remotes | git remote -v |
| Set origin | git remote set-url origin git@github.com:owner/repo.git |
Troubleshooting
| Problem | Fix |
|---|
| Remote not found | git remote add origin git@github.com:owner/repo.git |
| Wrong remote | git remote set-url origin <correct-url> |
| Parse failure | Check raw URL: git remote get-url origin |
Related Skills
- github MCP - Use extracted repo name with GitHub API
- github-actions-inspection - Pass repo to gh CLI commands
- git-workflow - Identify repo for workflow operations