Infra & Tools/GIT

Git remote branch 가져오기

sung.hyun.1204 2022. 9. 5. 11:09

-서문 

 

이전 글에서는 로컬의 git  branch 를 main을 제외하고 전부 삭제 하는 것을 다루었다 .

https://chosunghyun18.tistory.com/40

 

git branch clear , 모든 브랜치 삭제

local main , master 를 제외한 모든 branch 삭제 git branch | grep -v "master" | grep -v "main"| xargs git branch -D xargs : 모든 이름 grep : Global Regular Epression Print 파일에서 원하는 내용만 따로..

chosunghyun18.tistory.com

 

이번에는 github 에 있는 즉 , remote branch 를 가져 오는 것을 알아보자.

 

1 . remote branch  local 로 가져오기 . 

placesub 라는 remote branch 를 가져와보자.

1- 1. remote branch 업데이트 .

가져오기 전에 git remote 를 갱신해 준다.

 

git remote update

 

1-2 . 가져올 remote branch 확인

git branch -r

 

1-3 로컬의 동일 이름의  branch 로 만들기,  -t 를 옵션으로 적어준다. 

 git checkout -t  origin/placesub

 

 

git kraken 으로 확인한다.
remote branch 를 local 에 생성된것을 확인 가능하다.

 

Case 1)

 

어 ,, 난 이름 바꿔서 가져오고 싶어 !

 

$ git checkout -b [생성할 branch 이름] [원격 저장소의 branch 이름]

 

Case 2)

어 ,, 난 로컬로 소스를 보고 테스트 변경 해보고 싶은데, 올릴 생각은 없어!

 

$ git checkout [원격 저장소의 branch 이름]

‘detached HEAD’ 상태로 들어온다.

detached HEAD

소스를 보고 변경 해볼 수도 있지만 변경사항들은 commit, push 할 수 없다.

다른 branch로 checkout하면 사라진다.