Git
[Git] pull과 충돌
qoth_0
2023. 12. 11. 09:48
728x90
반응형
git pull과 충돌
- 수정 후 수정사항 업로드
- add, commit, push
- 수정사항 다운로드
- git pull
- origin이 수정되어 local과의 차이 발생시
- origin의 변경사항은 local에서는 추적불가능
- vscode의 source control의 변경사항 인지는 local repository에 대한 변경인지
→ push 했을 때 다른사람이 먼저 수정해서 올려놨으면 origin과 로컬이 다르기 때문에 내려받은 후 수정을 해야됨
- git pull origin 브랜치명
- ex)git pull origin main
- origin을 기준으로 local을 update
- fetch + merge까지 되는 것 → 바로 origin내용으로 바뀜
- pull은 working directory까지 반영
- 별도의 브랜치명 명시 안하면 현재 checkout 된 branch에서 pull
- 만약 로컬의 변경파일과 origin의 변경파일이 같이 변경되면 충돌발생 가능성
- 이 때는 git fetch 사용해서 비교한 후 merge 해야함
- ex)git pull origin main
실습
- origin main에서 test3.txt 파일 변경 발생
→ local에서 변경사항 인지 가능한지 vscode에서 확인, 소스트리도 확인



- 내 local에서 test3.txt 파일 변경하여 push 시도


- 충돌로 push 불가 → 일단 force를 통해 강제 push


⇒ git pull origin main하면 origin에서 바꾼 내용이 vs코드에 반영됨
- 로컬에서 test1.txt 파일 수정 후 커밋(push x), github에서 test2.txt 파일 수정 후 git pull - 서로 다른 파일

로컬 수정

커밋

github수정

git pull origin

⇒ test2.txt 내용이 로컬에도 반영됨 - 충돌 x (다른 파일이기 때문)
728x90
반응형