본문 바로가기
프로그래밍/Git

git push error: failed to push some refs to 해결가이드

by 서울에서 살아가기 2022. 7. 19.

 

초기 git 프로젝트 셋팅후에 작업을 진행할때 error: failed to push some refs to 'repo' 와 같은 오류를 한번씩 보셨을겁니다.

 

이는 원격저장소(gitlab/github)에 새로운 신규 파일이 생성되었고, 로컬저장소(내컴퓨터)에는 파일이 존재하지 않을 경우 내 파일을 로컬저장소 -> 원격저장소git push 명령어 수행시 발생하는 오류입니다.

 

 

 

 

오류 해결 가이드 (failed to push some refs to)

원인1. 원격저장소와 로컬저장소 파일이 맞지 않을때

로컬저장소에 있는 파일을 그대로 원격저장소에 저장한다면 기존 파일을 삭제하거나 덮여씌우는 문제가 발생할 수 있습니다. 이러한 문제를 막고자 git error: failed to push some refs to 와 같은 에러 메시지를 표출합니다.

 

! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.git.com/repo/project.git'

 

이 경우에는 원격저장소에 존재하는 파일을 내 로컬저장소에 git pull한 후 다시 push명령어를 수행해야 합니다.

아래 예시를 참고하여 해결을 진행해보겠습니다.

 

 

1. git pull 명령어를 통해 원격저장소에 있는 최신 파일들을 로컬저장소로 내려받는다.

> git pull https://gitlab.git.com/repo/project.git
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 1.64 KiB | 38.00 KiB/s, done.

 

2. git push 명령어를 통해 원격저장소에 데이터를 올려준다.

 

 

원인2.  git 계정에 push 권한이 없을때

git 계정에 push 권한이 없다면 아래와 같은 권한없음 오류가 표출됩니다.

 

remote: GitLab:
remote: A default branch (e.g. main) does not yet exist for Diagnostics/server/oem_test_kmc
remote: Ask a project Owner or Maintainer to create a default branch:
remote:
remote:   https://gitlab.gitauto.com/Diagnostics/server/oem_test_kmc/-/project_members
remote:

위와 같은 오류가 발생하는 이유로는 git repogitory를 생성한 후 developer 권한자는 초기 push를 진행할 수 없어서 발생하는 오류입니다.

 

 

해결방법

1. push 명령어를 수행하려는 계정에 maintainer 권한 또는 owner 권한을 할당합니다.

2. maintainer 권한자 또는 owner 권한자에게 해당 repogitory의 최초 push를 요청하거나 README.md 파일 생성을 요청한 후 진행합니다.

 

 

함께보면 좋은자료

>> git pull fatal: refusing to merge unrelated histories 에러 해결

 

 

 

 

 

 

반응형

댓글