[Git] error: refname refs/heads/master not found

깃 리포지토리 초기 생성 오류

깃허브에서 리포지토리를 생성하면 아래와 같이 실행해야 할 명령어들이 안내된다.

echo “# 2022_Library_Python” >> README.md
git init
git add README.md
git commit -m “first commit”
git branch -M main
git remote add origin https://github.com/HydroponicGlass/2022_Library_Python.git
git push -u origin main

위 명령어들에서 README파일 생성(echo…, git add…)은 무시해도 잘 되었었는데, 오늘 git branch -M main 단계에서 아래와 같은 오류가 출력되었다.

nothing to commit (create/copy files and use “git add” to track)
error: refname refs/heads/master not found

실패한 방법

구글에서 찾은 몇가지 방법을 시도했으나 다 실패했다.

1. git branch -M master main

애초에 master branch가 없다. git branch 명령어로 조회해보면 branch가 하나도 나오지 않는다.

2. git add . 

반응없음. 애초에 add할 파일이 없음

해결 방법

깃허브에서 안내한 명령어대로 전부 다 실행하면 잘 된다. 즉, README 파일이 존재하면 이상없이 실행된다.

Leave a Comment