🔥 git clone
Git 저장소를 복제하려면 git clone 명령어를 사용하면 됩니다. 이 명령어는 원격 저장소의 모든 데이터를 로컬 환경으로 가져와 작업할 수 있게 해줍니다.
기본 사용법
git clone <repository-url> 형식으로 간단하게 사용할 수 있습니다.
$ git clone https://github.com/codingmax-tube/git-commands-cookbook.git
# 지정한 URL의 저장소를 현재 디렉토리에 복제합니다.
Cloning into 'git-commands-cookbook'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), done.$ git clone https://github.com/codingmax-tube/git-commands-cookbook.git
# 지정한 URL의 저장소를 현재 디렉토리에 복제합니다.
Cloning into 'git-commands-cookbook'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), done.이렇게 하면 git-commands-cookbook라는 이름의 디렉토리가 생성되고, 그 안에 저장소의 내용이 복제됩니다.
git-commands-cookbook$ ls -al
total 24
drwxr-xr-x 6 codingmax staff 192 3 29 17:28 .
drwxr-xr-x 11 codingmax staff 352 3 29 17:30 ..
drwxr-xr-x 12 codingmax staff 384 3 29 17:28 .git
-rw-r--r-- 1 codingmax staff 2047 3 29 17:28 .gitignore
-rw-r--r-- 1 codingmax staff 1066 3 29 17:28 LICENSE
-rw-r--r-- 1 codingmax staff 23 3 29 17:28 README.mdgit-commands-cookbook$ ls -al
total 24
drwxr-xr-x 6 codingmax staff 192 3 29 17:28 .
drwxr-xr-x 11 codingmax staff 352 3 29 17:30 ..
drwxr-xr-x 12 codingmax staff 384 3 29 17:28 .git
-rw-r--r-- 1 codingmax staff 2047 3 29 17:28 .gitignore
-rw-r--r-- 1 codingmax staff 1066 3 29 17:28 LICENSE
-rw-r--r-- 1 codingmax staff 23 3 29 17:28 README.md디렉토리 이름 지정하기
저장소를 복제할 때 디렉토리 이름을 직접 지정하고 싶다면 아래와 같이 하면 됩니다.
$ git clone https://github.com/codingmax-tube/git-commands-cookbook.git my-repo
# 저장소를 'my-repo'라는 이름의 디렉토리에 복제합니다.
Cloning into 'my-repo'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), done.$ git clone https://github.com/codingmax-tube/git-commands-cookbook.git my-repo
# 저장소를 'my-repo'라는 이름의 디렉토리에 복제합니다.
Cloning into 'my-repo'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), done.이렇게 하면 my-repo라는 이름의 디렉토리가 생성되고, 그 안에 저장소의 내용이 복제되겠죠.
my-repo$ ls -al
total 24
drwxr-xr-x 6 codingmax staff 192 3 29 17:30 .
drwxr-xr-x 11 codingmax staff 352 3 29 17:30 ..
drwxr-xr-x 12 codingmax staff 384 3 29 17:30 .git
-rw-r--r-- 1 codingmax staff 2047 3 29 17:30 .gitignore
-rw-r--r-- 1 codingmax staff 1066 3 29 17:30 LICENSE
-rw-r--r-- 1 codingmax staff 23 3 29 17:30 README.mdmy-repo$ ls -al
total 24
drwxr-xr-x 6 codingmax staff 192 3 29 17:30 .
drwxr-xr-x 11 codingmax staff 352 3 29 17:30 ..
drwxr-xr-x 12 codingmax staff 384 3 29 17:30 .git
-rw-r--r-- 1 codingmax staff 2047 3 29 17:30 .gitignore
-rw-r--r-- 1 codingmax staff 1066 3 29 17:30 LICENSE
-rw-r--r-- 1 codingmax staff 23 3 29 17:30 README.md브랜치 지정하기
특정 브랜치만 복제하고 싶다면 -b 옵션을 사용하면 됩니다.
$ git clone -b develop https://github.com/codingmax-tube/git-commands-cookbook.git
# 'develop' 브랜치만 복제합니다.
Cloning into 'git-commands-cookbook'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), done.$ git clone -b develop https://github.com/codingmax-tube/git-commands-cookbook.git
# 'develop' 브랜치만 복제합니다.
Cloning into 'git-commands-cookbook'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), done.이렇게 하면 develop 브랜치만 복제되고, 자동으로 체크아웃까지 됩니다.
$ cd git-commands-cookbook
$ git branch
* develop$ cd git-commands-cookbook
$ git branch
* develop깊이 지정하기
저장소의 전체 히스토리가 필요 없고, 최신 커밋 몇 개만 필요하다면 --depth 옵션을 사용하세요.
$ git clone --depth 1 https://github.com/codingmax-tube/git-commands-cookbook.git
# 최신 커밋 1개만 포함하여 저장소를 복제합니다.
Cloning into 'git-commands-cookbook'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 2 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), done.
$ git clone --depth 1 https://github.com/codingmax-tube/git-commands-cookbook.git
# 최신 커밋 1개만 포함하여 저장소를 복제합니다.
Cloning into 'git-commands-cookbook'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 2 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), done.
이렇게 하면 저장소의 크기를 줄일 수 있고, 복제 속도도 빨라집니다.
$ cd git-commands-cookbook
$ git log
commit fe5b5e06fd88611c44d7630010e93bb01b4e48cb (grafted, HEAD -> main, origin/main, origin/HEAD)
Author: codingmax <codingmax@tv.local>
Date: Fri Mar 29 17:37:50 2024 +0900
update README.md$ cd git-commands-cookbook
$ git log
commit fe5b5e06fd88611c44d7630010e93bb01b4e48cb (grafted, HEAD -> main, origin/main, origin/HEAD)
Author: codingmax <codingmax@tv.local>
Date: Fri Mar 29 17:37:50 2024 +0900
update README.md서브모듈 포함하기
저장소에 서브모듈이 포함되어 있다면 --recursive 옵션을 사용하세요.
$ git clone --recursive https://github.com/codingmax-tube/git-commands-cookbook.git
# 저장소와 서브모듈을 모두 복제합니다.$ git clone --recursive https://github.com/codingmax-tube/git-commands-cookbook.git
# 저장소와 서브모듈을 모두 복제합니다.이렇게 하면 저장소와 함께 서브모듈까지 한 번에 복제할 수 있습니다.
git clone은 Git 협업 워크플로우의 시작점이라고 할 수 있습니다. 그렇기에 이 명령어를 잘 사용할 줄 안다면 프로젝트에 참여할 준비가 모두 끝난 것입니다. 마음껏 코딩하고, 커밋하고, 푸시하면서 프로젝트를 발전시켜 나갈 수 있죠.











