포스트

[GitHub 100일 챌린지] Day 25 - Repository Clone하기

[GitHub 100일 챌린지] Day 25 - Repository Clone하기

100일 챌린지 Day 25 - GitHub Repository를 내 컴퓨터로 가져옵니다

배울 내용

  1. git clone 사용하기
  2. HTTPS vs SSH 방식
  3. Clone 후 작업하기

Topic1. git clone 사용하기

git clone = GitHub Repository를 로컬로 복사

Clone 기본 사용법

해보기:

1
2
3
4
5
6
7
8
# 1. Clone할 위치로 이동
cd ~/projects

# 2. Repository Clone
git clone https://github.com/username/repository.git

# 3. 폴더 이동
cd repository

출력:

1
2
3
4
5
Cloning into 'repository'...
remote: Enumerating objects: 100, done.
remote: Counting objects: 100% (100/100), done.
remote: Compressing objects: 100% (80/80), done.
Receiving objects: 100% (100/100), done.

효과:

1
2
3
4
✅ 전체 히스토리 다운로드
✅ .git 폴더 포함
✅ 모든 파일과 폴더
✅ 최신 상태 (main 브랜치)

Repository URL 복사

GitHub에서 URL 가져오기:

1
2
3
4
5
1. Repository 페이지 접속
2. 초록색 "Code" 버튼 클릭
3. HTTPS 탭 선택
4. URL 복사
   https://github.com/username/repo.git

폴더명 지정

기본 (Repository 이름):

1
2
git clone https://github.com/user/awesome-project.git
# → awesome-project/ 폴더 생성

폴더명 변경:

1
2
git clone https://github.com/user/awesome-project.git my-project
# → my-project/ 폴더 생성

실습해보기

해보기:

1
2
3
4
5
6
7
8
9
# 연습용 Repository Clone
git clone https://github.com/github/gitignore.git

# 폴더 이동
cd gitignore

# 내용 확인
ls
git log --oneline

결과: GitHub의 Repository를 로컬로 복사할 수 있습니다


Topic2. HTTPS vs SSH 방식

Clone에는 두 가지 방식이 있습니다.

HTTPS 방식 (권장 - 초보자)

사용법:

1
git clone https://github.com/username/repo.git

장점:

1
2
3
4
✅ 설정 간단
✅ 어디서나 작동
✅ 방화벽 문제 없음
✅ 초보자 친화적

단점:

1
2
❌ Push 시 매번 인증 (처음에만)
  → Credential Helper로 해결

인증 방법:

1
2
3
Username: GitHub 사용자명
Password: Personal Access Token (PAT)
  ⚠️ 비밀번호 아님! Token 사용

SSH 방식 (고급)

사용법:

1
git clone git@github.com:username/repo.git

장점:

1
2
3
✅ 인증 필요 없음 (키 설정 후)
✅ 더 안전
✅ 자동화에 유리

단점:

1
2
❌ SSH 키 설정 필요 (복잡)
❌ 방화벽에서 막힐 수 있음

SSH 키 설정 (Day 9 참고):

1
2
3
4
5
6
7
8
# 1. SSH 키 생성
ssh-keygen -t ed25519 -C "your@email.com"

# 2. 공개 키 복사
cat ~/.ssh/id_ed25519.pub

# 3. GitHub에 등록
Settings → SSH keys → New SSH key

방식 비교

항목 HTTPS SSH
설정 쉬움 복잡
인증 Token SSH 키
보안 안전 더 안전
초보자 ✅ 권장
전문가 ✅ 권장

권장:

1
2
초보자: HTTPS 사용
경험자: SSH 사용

결과: Clone 방식의 차이를 이해합니다


Topic3. Clone 후 작업하기

Clone 한 Repository에서 작업하는 방법입니다.

Repository 상태 확인

해보기:

1
2
3
4
5
6
7
8
9
10
11
# 현재 브랜치 확인
git branch

# Remote 확인
git remote -v

# 상태 확인
git status

# 로그 확인
git log --oneline -5

출력:

1
2
3
4
5
* main
origin	https://github.com/user/repo.git (fetch)
origin	https://github.com/user/repo.git (push)
On branch main
Your branch is up to date with 'origin/main'.

파일 수정하기

해보기:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 1. 파일 수정
echo "## Installation" >> README.md

# 2. 상태 확인
git status

# 3. 스테이징
git add README.md

# 4. 커밋
git commit -m "Add installation section"

# 5. 히스토리 확인
git log --oneline -3

Remote와 동기화

최신 변경사항 가져오기:

1
git pull

내 변경사항 업로드:

1
git push

⚠️ Push 권한 필요:

1
2
3
본인 Repository: ✅ 가능
타인 Repository: ❌ 불가능
  → Fork 후 PR 필요

Clone vs Download ZIP

차이점:

1
2
3
4
5
6
7
8
9
10
11
git clone:
✅ .git 폴더 포함
✅ 전체 히스토리
✅ git 명령어 사용 가능
✅ Pull/Push 가능

Download ZIP:
❌ .git 폴더 없음
❌ 히스토리 없음
❌ git 명령어 불가
❌ 일회용 다운로드

언제 뭘 사용?:

1
2
개발/협업: git clone
단순 파일 보기: Download ZIP

실습 프로젝트

해보기: 자신의 Repository Clone하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 1. GitHub에서 my-first-repo URL 복사
# 2. 로컬에 Clone
git clone https://github.com/username/my-first-repo.git

# 3. 폴더 이동
cd my-first-repo

# 4. 파일 수정
echo "Local edit" >> README.md

# 5. 커밋
git add README.md
git commit -m "Edit from local"

# 6. Push
git push

결과: Clone한 Repository에서 작업하고 동기화할 수 있습니다


정리

완료 체크:

  • git clone을 사용할 수 있다
  • HTTPS와 SSH 차이를 안다
  • Clone 후 작업할 수 있다

핵심 명령어:

1
2
3
4
5
git clone URL            # Repository 복사
git clone URL 폴더명     # 폴더명 지정
git remote -v            # Remote 확인
git pull                 # 최신 가져오기
git push                 # 업로드

Clone 방식:

1
2
3
4
5
HTTPS (초보자):
git clone https://github.com/user/repo.git

SSH (경험자):
git clone git@github.com:user/repo.git

Week 5 완료! 🎉

다음 주에는 Git 핵심 개념을 배웁니다.

다음: Day 26 - Git 3영역 이해

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.