본문 바로가기
DevOps/Git

[해결 방법] fatal: The current branch main has no upstream branch

by HJ0216 2023. 1. 19.

발생 Error

Git Bash에서 다음 명령어를 입력할 경우,

$ git push

fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

 

fatal: The current branch main has no upstream branch

Error 발생

 

 

Error 원인

현재 브랜치의 원격 저장소 설정을 정확하게 하지 않았기 때문에 발생

 

 

해결 방법

git bash에 push를 안내대로 진행

$ git push --set-upstream origin main

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 263 bytes | 65.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/HJ0216/TIL.git
   681b6a8..3dc0358  main -> main
branch 'main' set up to track 'origin/main'.

git push --set-upstream origin main의 의미

➡️upstream: 로컬과 연결된 원격 저장소

로컬 저장소: origin의 원격 저장소를 main으로 지정하여, main으로 push하라는 의미

 

 

 

참고 자료

📑 [Git] 깃 오류 해결 fatal: The current branch master has no upstream branch.

📑  git 최초 push 시 왜 --set-upstream 옵션을 설정해야할까?