DEVOPS/GIT

[Git] remote branch 명령어

연듀 2021. 10. 21. 22:55

 

 

깃허브에 새로운 레퍼지토리를 생성하고 연결한다.

 

remote repository를 등록만 했기 때문에 아직 remote branch는 없다.

브랜치는 자동으로 원격에 등록되지 않는다.

 

push를 하면 remote repository는 로컬과 동일한 branch를 생성한다.

 

 

 

 

이름이 다른 branch로 연결하려면

git push origin [브랜치이름]:[새로운 브랜치 이름]

 

footer라는 브랜치를 function 이름으로 추가한다.

 

 

 

git clone을 해 브랜치를 확인해 보면 remote repository의 모든 branch정보를 다 가져오지는 않는다.

master branch 하나만 표시한다.

 

git branch -r / git branch -a

remote branch 정보를 확인

 

git branch -vv

 

현재 master branch가 remote repository의 origin/master로 upstream tracking 된다.

 

 

 

git checkout --track orgin/브랜치이름

 

원본 local repository에서 footer 브랜치를 funciton remote branch로 등록한다.

 

 

ahead 1

remote repository로 전송되지 않은 commit이 하나 있다는 의미 

 

 

 

gitstudy06_clone폴더에서 두번째 줄을 추가하고 원격 레퍼지토리에 push 한 후,

gitstudy06 폴더로 footer 브랜치에서 pull한다. 그럼 clone폴더에서 추가한 두번째 줄이 추가가 된 것을 볼 수 있다.

 

 

 

remote branch 복사

 

remote repository에 새롭게 branch 생성

 

 

 

git fetch

branch commit을 가져온다.

 

git branch -r

원격 브랜치 확인

 

 

git checkout -b newbranch origin/newbranch

 

fetch된 remote branch 목록을 이용하여 새로운 local branch 를 생성

 

 

 

브랜치 삭제

git branch -d [브랜치 이름]

 

현재 브랜치에서는 삭제할 수 없고 다른 브랜치로 이동 후 삭제해야한다.

최종 상태가 commit되어 깨끗한 스테이지 상태일때만 삭제 가능하다.

 

working directory나 stage에 추가 commit작업이 남아있는 경우에

git branch -D [브랜치이름]

 

하면 강제 삭제 가능하다.

 

 

 

 

git push origin --delete [remote브랜치]

 

원격 branch를 삭제한다.