Git & Github
[ git ] fatal: refusing to merge unrelated histories 해결
박개발
2023. 3. 16. 10:25
로컬 저장소의 프로젝트를 GitHub에서 만든 원격 저장소에 Push를 하려고 할 때
$ git push origin main
To github.com:somjang/test-repo.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'github.com:42maru-ai/hanmi-broker-api.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.
사실, 단순하게 생각하면 원격저장소에 있는 pull을 안해서 생긴 오류
이게 정답이기도하고..
$ git pull origin main
하지만? pull하려고 해도 오류..
From github.com:somjang/test-repo
* branch main -> FETCH_HEAD
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint:
hint: git config pull.rebase false # merge (the default strategy)
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: refusing to merge unrelated histories
흠.. 그래서 구글링 해보니,
신규로 만든 프로젝트에서 주로 발생하는데
서로 관련 기록이 없는 두 프로젝트를 병합할때 git이 거부를 한다고 합니다.
$ git pull origin main --allow-unrelated-histories
--allow-unrelated-histories 를 붙여 진행! 그럼 끝!