GrepBoard/매뉴얼
605 편 ·

pathspec did not match any file(s) 해결

·시험 환경 Ubuntu 24.04 (Docker) · git 2.43.0 · 2026-10·시험 범위 ↓·6 단계

pathspec did not match any file(s) known to git 은 그 이름의 브랜치·파일이 없다는 뜻입니다. 안 받은 원격 브랜치·대소문자·얕은 클론·cmd 따옴표를 봅니다.

output
error: pathspec 'fix-typo' did not match any file(s) known to git

git checkout <이름> 은 이름이 브랜치로 안 풀리면 파일 경로(pathspec)로 다시 해석하고, 그것도 없으면 이 오류를 냅니다. 브랜치를 꺼내려던 것이라면 대부분 원격 브랜치를 아직 받지 않았거나(git fetch), 이름의 대소문자가 다르거나, 얕은 클론이라 다른 브랜치를 받지 않게 묶여 있는 경우입니다. git commit -m 에서 나왔다면 Windows 명령 프롬프트의 작은따옴표 문제입니다.

[1] 원격 브랜치를 받아 왔는지 봅니다. 동료가 방금 만든 브랜치는 git fetch 전까지 로컬이 모릅니다. git switch 는 같은 상황에서 문구가 다릅니다.

console
$ git checkout fix-typoerror: pathspec 'fix-typo' did not match any file(s) known to git$ git switch fix-typofatal: invalid reference: fix-typo$ git branch -r  origin/HEAD -> origin/main  origin/feature-login  origin/main

git branch -r 목록에 없으면 받아 옵니다. 받은 뒤에는 같은 명령이 원격 브랜치를 따라가는 로컬 브랜치를 알아서 만듭니다.

console
$ git fetch originFrom /srv/remote * [new branch]      fix-typo   -> origin/fix-typo$ git checkout fix-typoSwitched to a new branch 'fix-typo'branch 'fix-typo' set up to track 'origin/fix-typo'.

[2] 이름을 글자 그대로 맞춥니다. 브랜치 이름은 대소문자를 가립니다. 원격에 실제로 어떤 이름이 있는지는 서버에 직접 물어보면 확실합니다.

console
$ git checkout main && git checkout Feature-LoginSwitched to branch 'main'Your branch is up to date with 'origin/main'.error: pathspec 'Feature-Login' did not match any file(s) known to git$ git ls-remote --heads origin342560e91c3fcc578a0b9dd9c71b822c3e8a5f59	refs/heads/feature-login1ff58fdcb716367e8031c359aa3aa01ac9bad658	refs/heads/fix-typodd7f4d6c2109b7333647f76452497edb37aa4fcf	refs/heads/main

git ls-remote 는 fetch 없이 원격의 현재 브랜치를 보여 줍니다. 여기 있는데 git branch -r 에 없다면 [1]이나 [4]입니다.

[3] 원격이 둘 이상이면 어느 쪽을 따라갈지 지정합니다. 포크 작업에서 origin 과 upstream 에 같은 이름의 브랜치가 있으면 자동 생성이 멈춥니다.

console
$ git checkout feature-loginhint: If you meant to check out a remote tracking branch on, e.g. 'origin',…fatal: 'feature-login' matched multiple (2) remote tracking branches$ git switch -c feature-login --track origin/feature-loginSwitched to a new branch 'feature-login'branch 'feature-login' set up to track 'origin/feature-login'.

늘 origin 을 고르게 하려면 git config checkout.defaultRemote origin 을 둡니다(git switch 에도 적용됩니다).

[4] 얕은 클론이면 받을 브랜치 목록부터 넓힙니다. git clone --depth 1 은 --single-branch 를 함께 켜서, 그 뒤의 git fetch 도 기본 브랜치 하나만 받습니다(git clone 문서: --depth 는 --single-branch 를 함의).

console
$ git config --get-all remote.origin.fetch+refs/heads/main:refs/remotes/origin/main$ git fetch origin && git branch -r  origin/HEAD -> origin/main  origin/main$ git checkout feature-loginerror: pathspec 'feature-login' did not match any file(s) known to git

fetch 를 해도 origin/main 하나뿐인 것이 신호입니다. 받을 범위를 모든 브랜치로 바꾸고 다시 받습니다.

console
$ git remote set-branches origin '*' && git fetch -q --depth 1 origin && git checkout feature-loginSwitched to a new branch 'feature-login'branch 'feature-login' set up to track 'origin/feature-login'.

브랜치 하나만 필요하면 git remote set-branches --add origin feature-login 으로 그 하나만 더합니다. 이 명령은 받을 범위만 바꾸고 브랜치를 가져오지는 않으니, 이어서 git fetch origin(얕은 클론이면 --depth 1)과 git checkout feature-login 을 다시 칩니다.

[5] git commit -m 에서 나왔다면 따옴표를 큰따옴표로 바꿉니다. Windows cmd.exe 는 작은따옴표를 묶음으로 보지 않아서 git commit -m 'fix typo' 가 git 에는 -m "'fix" 와 "typo'" 두 인자로 넘어갑니다. 두 번째 인자는 커밋할 파일 경로로 읽힙니다. 아래는 그렇게 넘어온 인자를 그대로 재현한 것입니다.

console
$ git commit -m "'fix" "typo'"error: pathspec 'typo'' did not match any file(s) known to git

cmd.exe 에서는 git commit -m "fix typo" 로 씁니다. PowerShell·Git Bash 에서는 작은따옴표도 제대로 묶입니다. 오류 문구 속 이름 끝에 ' 가 붙어 있으면('typo'', 'commit'') 이 경우입니다.

[6] 파일을 다루던 중이면 경로를 확인합니다. git add·git rm 은 fatal: 로 시작하는 비슷한 문구를 냅니다.

console
$ git add docs/guide.mdfatal: pathspec 'docs/guide.md' did not match any files$ git ls-files docsdocs/Guide.md$ touch notes.txt && git rm notes.txtfatal: pathspec 'notes.txt' did not match any files
명령이 문구가 뜻하는 것
git add <경로>작업 폴더에 그 경로가 없습니다(대소문자 포함)
git rm <경로>Git 이 추적하지 않는 파일입니다 — 그냥 rm 으로 지웁니다
git checkout -- <경로>인덱스에 그 경로가 없습니다

스크립트에서 없는 파일 때문에 멈추지 않게 하려면 git rm --cached --ignore-unmatch <경로> 처럼 --ignore-unmatch 를 씁니다. 종료 코드가 0 으로 끝납니다.

브랜치를 받은 뒤 푸시가 ! [rejected] 로 막히면 git push rejected 해결을 봅니다.

공식 근거: git-checkout — --guess · checkout.defaultRemote · git-switch · git-clone — --depth · --single-branch · git-remote — set-branches · gitglossary — pathspec

#git#git-checkout#git-switch#pathspec