새벽코딩

Git Push rejected (Updates were rejected) error 본문

Programming/git

Git Push rejected (Updates were rejected) error

midnightcoder 2022. 8. 6. 05:23

파이참(PyCharm)에서 터미널을 이용하여 bitbucket에 push를 할때, 아래와 같은 에러가 발생하였다.

 

 

Document
PS C:\Users\lunat\Desktop\********\********> git push -u origin master
To https://*************/*******/*******
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://bitbucket.org/*****/******'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

에러의 원인은 remote 저장소와 local 저장소의 현재 상태가 달라서 발생한것이다.

 

하지만, 친절하게 에러에 대한 hint로 push전에 pull를 해보았다.

 

PS C:\Users\lunat\Desktop\*****\*****> git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

이번엔, 위와같은 문제로 다시 push가 안되었다.

 

그래서 위에 메세지에서 알려주는대로 다시한번, 시도를 해보았다.

 

PS C:\Users\lunat\Desktop\*****\****> git branch --set-upstream-to=origin/master master
Total 13963 (delta 3846), reused 13955 (delta 3843), pack-reused 0
remote: Resolving deltas: 100% (3846/3846), done.
To https://bitbucket.org/****/******
   78b1e81..8c19c33  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

해당 명령어로, Branch 'master' 가 'origin'으로 부터 추적이될 수 있도록 셋업이 되었고

 

remote 저장소에 모든 데이터가 잘 push되었다.

 

'Programming > git' 카테고리의 다른 글

.gitignore 만들기 (git commit에서 자동 제외)  (0) 2022.10.08