ubuntu@server:~/PythonHome/TestTA/api$ git push --set-upstream origin master
Username for 'https://github.com': SOMJANG-42MARU
Password for 'https://SOMJANG-42MARU@github.com':
To https://github.com/SOMJANG-42MARU/MaruKeyword.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SOMJANG-42MARU/MaruKeyword.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
github에 업로드를 하고싶은 디렉토리에서
$ git init
위의 명령어로 초기화를 하고
$ git remote add origin https://~
위의 명령어를 통해 원격 저장소 설정을 한 이후에도
git pull 또는 git merge 명령어를 시도하면 오류가 나서
$ git push origin master
위의 명령어를 통해 처음 push를 하려고 할때 push를 할 수 없는 경우 원인과 해결방법은 다음과 같습니다.
원인은 .gitignore 파일 또는 README.md 파일로 인해 발생한다고 합니다.
해결 방법은 push하려고하는 브랜치 이름 앞에 + 를 붙여 push 하면 됩니다.
$ git push origin +master
ubuntu@server:~/PythonHome/TestTA/api$ git push origin +master
Username for 'https://github.com': SOMJANG-42MARU
Password for 'https://SOMJANG-42MARU@github.com':
Counting objects: 15, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (15/15), 9.86 KiB | 0 bytes/s, done.
Total 15 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/SOMJANG-42MARU/MaruKeyword.git
+ c3192b8...253ecd4 master -> master (forced update)
만약! 기존에 작업한 내용이 있다고 한다면 ( master branch 일 경우 - main일 경우 master -> main 변경)
$ git pull origin master --allow-unrelated-histories
위의 명령어를 통해 먼저 pull 받은 뒤에 push 를 진행해보시는 것을 추천드립니다.
읽어주셔서 감사합니다.