본문 바로가기

FE/git || github

[ git/clone ] git 클론 하기(특정 브런치 가져오기)

git clone

git clone <repository_url> -b <branch_name> <local_repository_name>

 

  • git clone: This is the main command for cloning a Git repository.
  • <repository_url>: This is the URL of the remote repository you want to clone from.
  • -b <branch_name>: This option specifies the branch you want to clone.
  • <local_repository_name> (optional): This is the name of the local directory where you want to clone the repository.

 

예시

git clone https://github.com/user/repository.git -b feature-branch my-local-repository

 

 

특정 브랜치만 clone 2가지 방식

git clone -branch <branch_name> [REPOSITORY_URL]
git clone -b <branch_name> --single-branch [REPOSITORY_URL]

 

git clone -b <branch_name> git clone -b <branch_name> --single-branch
든 브런치(레포지토리)의 히스토리(history) 다 가지고 옴 특정 브런치의 히스토리만 가져옴
자동으로 checkout <branch_name>으로 이동 그냥 다운로드만 해줌

 

 

 

어떻게 하는가?

1. terminal에서 cd(리눅스 용어)를 통해 원하는 위치로 이동한다.

2. 그리고 거기서 위의 2가지중 명령어 하나를 사용한다.

  • a) git clone -b {branch_name} --single-branch {저장소 URL} {폴더명}
  • b) git clone -b {branch_name} {저장소 URL} {폴더명}
  • c) git clone {brnach URL} {컴퓨터 폴더명}

3.  폴더 검색기(findder or window탐색기)를 통해서 위치로 찾아간다.

4. vs code를 통해서 파일을 연다. npm init 설치한다. (create-react-app or vite 등을 먼저 설치해도 된다고 하는거 같은데(?)
통상적으로 github에 올리는 파일들은 node_module을 같이 올리지 않는다. 따라서 node를 실행 시킬 수 있는 npm or yarn 등이 필요한 것으로 알고 있다.

 

 

 

 

git pull 이 안 될때 크게 2가지 오류

1. github의 readme.md 파일 생성으로 인해 local 과 remote의 차이

 

2. 두개의 commit 히스토리가 서로 관련이 없기 때문에 merge 할 수 없다는 뜻

다만, 이 둘을 활용해도 안될 시,

 

 

 

아래글에서 상세한 설명 읽을 수 있음.

https://velog.io/@hill0ne/git-push-%EC%98%A4%EB%A5%98-Updates-were-rejected-because-the-tip-of-your-current-branch-is-behind