local 과 원격 branch 연동

최문길·2023년 11월 11일
1

요약

  1. local branch (vscode등...) 생성 - git branch test
  2. git push origin test
  3. git branch --set-upstream-to origin/test ( 아니면 git push -u origin test )
    ( = git push -u origin [연동시킬 remote브랜치명] )
  4. git branch -r ( 원격 브랜치에 머머머 있는지 local vsCode 등, terminal에서 확인 하고 싶으면 치는 명령어 )

0. local과 원격을 연결 시켜주자

local의 작업할 폴더와 github의 repo를 연동시켜주는 것이 먼저임

<My local vsCode terminal>

git remote add origin '연동시킬 reop의 주소'

이 글의 주제는 '내 작업 폴더의 특정 branch'를 원격에도 만들어주고

local의 특정 branch와 원격에도 만들어준 특정 branch를 연결시켜

원격에 있는 특정 branch에만 내 특정 local branch의 commit 내역을 올리려고 하는 것이다.

따라서..

먼저 내 작업폴더와 + remote repo를 연결 시켜주는 것이 첫 번째이다.

1. local에 branch 만들기

<My local vsCode terminal>
git branch test

//아니면
git checkout -b test // test라는 branch를 만들고 test브랜치로 옮기기 라는 명령어 

2. 원격 저장소(repo)에도 똑같은 branch 심어주기

" git push origin [원격 repo에도 똑같이 심어줄 local branch명] "

<My local vsCode terminal><test branch에 있음>
  
 git push origin test// test라는 브랜치를 원격에 심어주는 명령어

3. conneting test-branch with repo test-branch

  1. " git --set-upstream-to origin/[연동시킬 remote 브랜치명] "
  2. " git push -u origin [연동시킬 remote브랜치명] "
<My local vsCode terminal><test branch에 있음>
  
 git branch --set-upstream-to origin/test
//아니면
git push -u origin practice-router

그 이후에

local에서 연동시킨 branch로 switch || checkout 하면

Your branch is up to date with 'origin/practice-styled
라는 문구가 뜬다.

git push

이젠 연동된 branch 마다

git push

명령어만 입력 해주면 된다.

다른 유용한 명령어

간혹 깃헙 페이지에서 GUI로 삭제 처리를 한경우 해당 로컬 저장소 커멘드라인에서

원격브랜치 목록 조회를 했을 때, 삭제했음에도 불구하고 여전히 브랜치가 보이는 경우가 있다고 한다.

이런 경우 아래 명령어로 로컬과 원격 브랜치를 동기화 할 수 있다.

git fetch --all --prune

0개의 댓글