몇 달 전에 레포지토리만 만들고 제대로 푸시를 하지 않은 레포에서 작업을 하다가 푸시가 안되는 현상을 마주했다.
PS C:\Desktop\study-nestjs\project> git push
Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>
PS C:\Desktop\study-nestjs\project> git push origin main
error: src refspec main does not match any
error: failed to push some refs to 'origin'
PS C:\Desktop\study-nestjs\project> git remote add origin https://github.com/nari1021/study-nestjs.git
PS C:\Desktop\study-nestjs\project> git push origin main
error: failed to push some refs to 'https://github.com/nari1021/study-nestjs.git'
Pull 도 안되고 Push 도 안되는 현상.
fatal: refusing to merge unrelated histories
이라는 에러와 함께 아무것도 되지않았는데,
git pull origin main --allow-unrelated-histories
--allow-unrelated-histories
옵션을 주면 강제로 pull이 일어나게 되고, 해결되었다.
PS C:\Desktop\study-nestjs\project> git pull origin main --allow-unrelated-histories
From https://github.com/nari1021/study-nestjs
* branch main -> FETCH_HEAD
CONFLICT (add/add): Merge conflict in README.md
Auto-merging README.md
CONFLICT (add/add): Merge conflict in .gitignore
PS C:\Desktop\study-nestjs\project>
On branch master
Your branch is up to date with 'origin/master'.
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both added: README.md
PS C:\Desktop\study-nestjs\project> git add .
PS C:\Desktop\study-nestjs\project> git commit -m "fix :: --allow-unrelated-histories 강제 결합"
PS C:\Desktop\study-nestjs\project> git push
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 805 bytes | 805.00 KiB/s, done.
Total 4 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To https://github.com/nari1021/study-nestjs.git
f4edee3..52d1261 master -> master
PS C:\Desktop\study-nestjs\project>
강제로 git에서 무언가를 하는 것은 좋지 않지만..
불가피하게 이전에 다른 노트북에서 작업하다가 제대로 마무리를 못한 나와 같은 경우에서는 꼭 필요한 옵션인것같다.
오늘도 이렇게 깃에 대해 하나 더 알아간다..!