본문 바로가기
dev/Git

[Git] Mac Git push/pull error 해결 방법

by sshnnne 2022. 7. 1.

 

git push origin master를 했을 때

 

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

 

이런 문구가 뜨신다면 어서오세요

 

-

 

이런 경우 remote 저장소를 등록해주지 않아서 생긴 문제입니다. cmd or 터미널에 

git remote -v

를 입력했을 때 아무것도 뜨지 않는다면 저장소가 등록되지 않은 것이기 때문에, push/pull 하기 전에 등록해주어야 합니다.

 

혹은 기존에 연결되어 있는 저장소와 내가 push/pull 하려는 저장소가 달라 발생할 수도 있습니다. 이 경우 기존 저장소를 삭제하고 다시 새롭게 연결해주시면 됩니다.

git remote remove origin

으로 기존에 연결된 저장소를 삭제합니다.

 

- remote 연결 방법

git remote add origin "연결하고자 하는 git 주소"

를 입력하시고, 

 

git remote -v

를 입력했을 때 fetch와 push 주소가 동일하면 올바르게 연결된 것입니다.

 

 

앗 이렇게 연결했는데도 git pull origin main을 했을 때 머 어쩌구저쩌구 뜨다가

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

이런 경고가 뜨면서 push/pull이 안 될 때는 git pull하는 방식을 제대로 구성하지 않은 것입니다.

 

여기서 제시하는 세 가지 방법에는 

 

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

 

가 있습니다.

 

rebase란?

: 공통 base를 가진 branch에서 한 branch의 base를 다른 branch의 최신 commit으로 branch의 base를 옮기는 작업입니다. (베이스 재설정)

공유 branch의 최신 커밋을 즉각 반영할 수 있습니다. 또한 커밋 이력을 남기지 않아 commit history가 깔끔해집니다.

(출처 : https://seosh817.tistory.com/240)

 

fast-forward란?

: merge의 한 종류로, 현재 branch의 HEAD를 대상 branch의 HEAD로 옮기는 merge

 

 

1) git config pull.rebase false  # merge (the default strategy)

: pull 할 때 rebase 하지 않고 merge 하는 것

 

2) git config pull.rebase true   # rebase

: pull 할 때 rebase 하는 것

 

3) git config pull.ff only 

: fast-forward 일 때만 pull 할 수 있음

 

세 개의 명령어 중 본인에게 적합한 명령어 터미널에 입력하시면 됩니다. 그리고 다시 git pull origin main 해주시면 완성 👏🏻

 

'dev > Git' 카테고리의 다른 글

[Git] Git 초기설정 하는 방법  (0) 2022.07.01
[GitLab] Mac SSH key 생성 및 등록  (0) 2022.06.30