본문 바로가기
utils/git and github

[Git] clone: 원격저장소 복제

by ds31x 2024. 5. 27.

git clone <원격저장소_url>

git clone은 Git 저장소를 복제하는 데 사용되는 명령어임.

 

원격 저장소의 전체 콘텐츠를 로컬 디렉토리에 복사하여 로컬에서 작업할 수 있게 해줌.

 

remote를 통한 연결보다 처음 프로젝트 참여시 보다 많이 사용되는 방법임.

2024.05.26 - [utils/git and github] - [Git] remote, remote add, remote show: 원격저장소와 연결

 

[Git] remote, remote add, remote show: 원격저장소와 연결

git remote add origin : 원격저장소 연결Local repository와 remote repository를 연결.Remote repository의 단축이름(별칭)을 보통 origin으로 지정.이후, Remote repository url 대신 단축이름(별칭, alias) 으로 처리 가능함.

ds31x.tistory.com


git clone 명령어의 기본 사용법

1.기본 형식:

git clone <repository_url>
  • 여기서 <repository_url>은 복제하려는 Git 저장소의 URL.

2.예시:

GitHub에 있는 공개 저장소를 복제하는 예시:

git clone https://github.com/username/repository.git
  • 이 명령어는 repository를 로컬 머신에 복제함.

git clone 명령어의 다양한 옵션

1.디렉토리 이름 지정:

git clone <repository_url> <directory_name>
  • 저장소를 특정 디렉토리 이름으로 복제하려면 위와 같은 형식을 사용한다.

 

git clone https://github.com/username/repository.git mydirectory
  • 이 명령어는 repositorymydirectory라는 이름의 디렉토리에 복제.
  • mydirectory 를 생략하면 저장소의 이름으로 디렉토리가 생성됨.

2.브랜치 지정:

git clone -b <branch_name> <repository_url>
  • 특정 브랜치를 복제하려면 -b 옵션을 사용하여 지정 가능함.

 

git clone -b develop https://github.com/username/repository.git
  • 이 명령어는 develop 브랜치를 복제.

3.Shallow Clone:

git clone --depth <depth> <repository_url>
  • 히스토리의 일부분만 복제하려면 --depth 옵션을 사용.

 

git clone --depth 1 https://github.com/username/repository.git
  • 이 명령어는 최신 커밋만 복제했음.

git clone의 단계별 절차

  1. 저장소 URL 확인:
    • 복제하려는 저장소의 URL을 확인한다.
    • 보통 GitHub, GitLab, Bitbucket 등의 원격 저장소에서 URL을 확인할 수 있음.
  2. 터미널 열기:
    • 터미널(또는 명령 프롬프트)을 열기.
  3. 명령어 실행:
    • 위에서 설명한 형식에 맞게 git clone 명령어를 입력하고 실행.
  4. 결과 확인:
    • 지정한 디렉토리에 저장소가 복제되었는지 확인.

이 과정은 원격 저장소의 전체 내용을 로컬에서 사용할 수 있게 해준다.


이후에는 일반적인 Git 명령어(git add, git commit, git push, git pull 등)를 사용하여 로컬 저장소와 원격 저장소 간의 작업을 이어갈 수 있음.


같이 읽어보면 좋은 자료들

2024.05.20 - [utils/git and github] - [Git] Git Summary (작성중)

 

[Git] Git Summary (작성중)

git이란2024.05.20 - [utils/git and github] - Git : 소개 git 설치 후 해줘야 하는 작업들[Git] git 설치 후 우선 해줘야 하는 작업들 (tistory.com)local repository 초기화2024.05.20 - [utils/git and github] - [Git] init : local rep

ds31x.tistory.com

 

 


 

728x90

'utils > git and github' 카테고리의 다른 글

[Git] rebase: Tutorial  (0) 2024.05.28
[Git] pager 옵션 조정  (0) 2024.05.27
[Git] Tutorial: remote repository  (0) 2024.05.26
[Git] Remote Repository  (0) 2024.05.26
[Git] remote, remote add, remote show: 원격저장소와 연결  (0) 2024.05.26