CI CD/GitHub

[GitHub] 깃허브 git push "error: failed to push some refs to" 에러 해결 방법

Nirsa 2020. 3. 19. 14:29
반응형

 

 

  • Git Push "error: failed to push some refs to" 에러 해결 방법

git push 할 때 아래와 같은 에러가 발생할 수 있습니다. 해당 에러는 github에 있는 파일과 현재 push 하려는 commit이 일치하지 않아 발생 합니다.

아래 이미지와 같은 상황일 때 github에는 README.md와 git-test.txt 파일이 있지만, Local에는 git-test.txt 파일이 없어서 파일 손실 우려로 인해 git에서 에러를 내뱉는 것 입니다.

 

저의 경우 아래와 같이 git clone으로 원본 파일을 가져오고, 누락된 git-test.txt 파일을 작업 디렉토리로 가져온 후 생성된 프로젝트 파일 삭제하여 push에 성공 하였습니다.

git push -f origin master와 같이 강제로 덮어 씌울 수 있으나, 파일 손실의 위험이 있습니다.

[root@docker-control devops]# git clone https://github.com/islandtim/Nirsa-Project.git
Cloning into 'Nirsa-Project'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 9 (delta 1), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), done.
[root@docker-control devops]# mv Nirsa-Project/git-test.txt ./
[root@docker-control devops]# ls -lh
total 8.0K
drwxr-xr-x. 2 root root 23 Mar 19 05:08 error_test
-rw-r--r--. 1 root root  5 Mar 19 05:24 git-test.txt
drwxr-xr-x. 3 root root 35 Mar 19 05:24 Nirsa-Project
-rw-r--r--. 1 root root 16 Mar 19 04:39 README.md
drwxr-xr-x. 2 root root 24 Mar 19 05:08 worker
[root@docker-control devops]# rm -rf Nirsa-Project/
[root@docker-control devops]# ls -lh
total 8.0K
drwxr-xr-x. 2 root root 23 Mar 19 05:08 error_test
-rw-r--r--. 1 root root  5 Mar 19 05:24 git-test.txt
-rw-r--r--. 1 root root 16 Mar 19 04:39 README.md
drwxr-xr-x. 2 root root 24 Mar 19 05:08 worker
[root@docker-control devops]# 
[root@docker-control devops]# git add *
[root@docker-control devops]# git commit -m "error"
[master (root-commit) 4e6358a] error
 Committer: root <root@docker-control.asia-northeast3-a.c.docker-project-271503.internal>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
    git config --global user.name "Your Name"
    git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
    git commit --amend --reset-author

 

  • Push 에러 발생 시 github

 

  • Push 에러 해결 후 github

 

반응형