Git (4)_Remote 복제(Git Clone), Branch

Jio.B·2023년 7월 31일
0

(ZB) DS 16기_part06_Git

목록 보기
4/9

기업에 입사하였을때, 상황을 재연한다면..
조직이 사용해온 기존 Remote repository가 존재하지만
Local Repository(개인 서버)는 생성하지 않은 상태에서 모든 업무를 시작하게될 것.
이럴 때 가장 먼저 해야할 일은 이 Remote repository를
나의 Local repository로 복제하기 >> 해당 명령어 : Git clone

Git Clone

    1. 사용할 폴더 생성
    1. Git init (폴더 초기화)
    1. Remote Repository 등록
    1. Remote Repository 내용을 pull
  • 1~4.에 해당하는 모든 과정을 Git clone 명령어로 해결할 수 있음
git clone https://github.com/<repository>.git
  • git clone with username and token
git clone https://<username>:<token>@github.com/<repository>.git

Branch

Branch 조회

  • local에서 생성한 brach는 반드시 push 해야만 local과 remote가 같은 내용을 공유할 수 있음
git branch      # local branch만 조회(검색)하는 명령어

git branch -r   # remote branch

git branch -a   # local과 remote branch를 함께 조회

Branch 생성

git branch <brnach name> 

Branch로 이동

git checkout <branch name>

Branch 생성 & 이동

  • 'branch01'이라는 이름의 brnach가 없다면 생성 후 branch01로 이동
  • 'branch01'이라는 이름의 brnach가 이미 존재한다면 에러코드 나타남
git checkout -b <branch01>

Local에서 만든 Branch ---> Remote에 적용

git push origin <branch name>

Local Branch 삭제

  • 단, 현재 위치가 삭제하려는 Local Branch와 일치한다면 에러 발생
    (local에서 'git branch' 명령어 입력 ---> 이름 옆에 별(*) 표시가 있는 것 = 현재 위치)

    [에러발생 문구] User@DESKTOP ~/HelloGit (branch02)
    $ git branch -d branch02
    error: Cannot delete branch 'branch02' checked out at 'C:/Users/HelloGit'

  • 'git checkout' 명령어로 main 또는 다른 branch로 이동 후 삭제 실행
git branch -d <branch name>

git branch -d branch02   # 예시

Local에서 Branch를 삭제한 상황을 remote에 적용

git push origin --delete <branch name>
  
git push origin --delete branch02  # 예시  

0개의 댓글

관련 채용 정보