새소식

🍪 Study

[git/github] error: src refspec master does not match any

  • -
728x90

로컬 저장소 프로젝트의 변경 사항을 github으로 push하면서 에러가 발생했다.

 

발생 원인

  • push하려는 branch가 생성되지 않은 경우 발생한다.
  • 원격 저장소에 올릴 때 명령어가 꼬이는 경우 발생한다.

 

해결 방법

default branch로  main  이 생성된다.

이 때 생성되지 않은 branch master로 push를 하려는 경우 해당 에러가 발생할 수 있다.

 

1. main branch로 push하기

: main branch로 push를 하는 방법을 사용할 수 있다.

git push -u origin main

 

2. 새로운 branch 만들기

:아래 명령어를 사용해 master branch를 만들어 사용한다.

git checkout -b 'master'
git push origin master

추가) git add .

local의 directory를 새로 생성한 repository와 remote add한 직후 push하려하는 경우, 해당 에러가 발생할 수 있다.

이때는 local directory에 속한 모든 파일을 git add하여 push하는 방법으로 해결할 수 있다.

git add .
git commit -m "commit content" // 생략 가능
git push -u origin main
728x90
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.