콘텐츠로 건너뛰기

[Git] 원격 저장소 복사하기 – git clone

원격 저장소에 있는 프로젝트를 사용하기 위해서는 git clone 명령을 사용하여 로컬 저장소에 프로젝트를 복사(다운로드)해야 합니다.

프로젝트 복사 방법

  1. 복사할 원격 저장소 접속
  2. Code 버튼을 눌러 git 원격 저장소 주소 복사
  3. 로컬 PC에서 프로젝트를 폴더로 이동
  4. git clone 명령을 사용하여 로컬 저장소에 복사

git clone (원격 저장소 복사)

저는 이전 포스트에서 생성한 원격 저장소를 복사해보겠습니다.

[그림 1]과 같이 Git 주소를 복사합니다.

그림 1. GitHub Repository 화면

복사할 위치로 이동 후 git clone <저장소 주소> 를 입력하고, 정상적으로 프로젝트를 복사하면 해당 폴더 하위에 프로젝트 이름 폴더가 생긴 것을 확인할 수 있습니다.

저는 아래와 같이 https://github.com/whalec-project/git-tutorial.git 저장소를 복사했으며, 하위 폴더에 git-tutorial 폴더가 생성된 것을 확인할 수 있습니다.
( 해당 주소는 public 저장소이므로 해당 주소로 테스트 하셔도 됩니다. )

$ cd ~/Mine/Dev
$ git clone https://github.com/whalec-project/git-tutorial.git
Cloning into 'git-tutorial'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
$ ls -al
total 8
drwxr-xr-x@  4 pgkang  staff  128  1  9 23:48 .
drwxr-xr-x@  4 pgkang  staff  128  1  9 23:59 ..
drwxr-xr-x@ 12 pgkang  staff  384  1  9 23:48 .git
-rw-r--r--@  1 pgkang  staff   50  1  9 23:48 README.md
$ cat README.md
# git-tutorial
public repository for git tutorialCode language: Bash (bash)

만약, 프로젝트 이름 대신에 다른 이름으로 폴더를 생성하고 싶으면 git clone <저장소 주소> <폴더 이름> 과 같이 입력하면 됩니다.

$ cd ~/Mine/Dev
$ git clone https://github.com/whalec-project/git-tutorial.git GitTest
Cloning into 'GitTest'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
$ cd GitTest
$ ls -al
total 8
drwxr-xr-x@  4 pgkang  staff  128  1  9 23:59 .
drwxr-xr-x@  4 pgkang  staff  128  1  9 23:59 ..
drwxr-xr-x@ 12 pgkang  staff  384  1  9 23:59 .git
-rw-r--r--@  1 pgkang  staff   50  1  9 23:59 README.mdCode language: Bash (bash)

git clone -b

git clone 시 기본 저장소의 내용을 복사합니다.

git clone -b <branch> <저장소 주소>와 같이 입력하면 저장소의 특정 branch에 있는 내용을 복사합니다.

$ git clone -b develop https://github.com/whalec-project/git-tutorial.git git-tutorial-dev
Cloning into 'git-tutorial-dev'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (6/6), done.
$ git branch
develop
$ ls
total 16
drwxr-xr-x@  5 pgkang  staff  160  1 12 10:25 .
drwxr-xr-x@  5 pgkang  staff  160  1 12 10:25 ..
drwxr-xr-x@ 12 pgkang  staff  384  1 12 10:25 .git
-rw-r--r--@  1 pgkang  staff   50  1 12 10:25 README.md
-rw-r--r--@  1 pgkang  staff   24  1 12 10:25 first.mdCode language: Bash (bash)

태그:

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다