C.W.K.
Stream
Lesson 01 of 05 · published

git init vs git clone

~16 min · init, clone

Level 0Untracked 새싹
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

처음부터는 init, 어딘가에서 가져오면 clone

디스크에 Git repo 띄우는 두 가지 방법: history 를 같이 들고 오거나 (git clone), 새 history 를 시작하거나 (git init). 표면적으론 둘 다 .git/ 폴더를 만들지만 결과가 달라. 어느 쪽 원하는지 아는 게 daily loop 의 출발점이야.

git init 은 현재 디렉토리에 빈 repo 를 만들어. commit 없고, 첫 commit 만들기 전엔 branch 도 없고, remote 도 없어. default branch 이름은 init.defaultBranch 따라가 (global 에 main 으로 박아둬, 옛 default master 는 미관리 Linux 짐이야). git init 다음엔 보통 시작용 .gitignore 쓰고, git add . 하고, 첫 commit 으로 프로젝트 history 를 실제로 시작해.

git clone 은 기존 repo 를 받아와. 기본으로 모든 branch 를 remote-tracking ref 로 복사하고 (origin/main, origin/feature 등), default branch checkout, clone URL 가리키는 origin 이라는 remote 까지 세팅해. SSH URL (git@github.com:user/repo.git) 은 매일 password 프롬프트 안 뜨게 해주고, HTTPS URL (https://github.com/user/repo.git) 은 막힌 회사 네트워크 포함 어디서나 되지만 token 이나 credential helper 가 필요해.

큰 repo 는 clone trick 두 가지 알면 좋아. --depth 1 은 shallow clone — 최신 commit 만, history 없이. 빠르지만 blame, bisect 가 의미 없어. --filter=blob:none 은 partial clone — commit graph + tree 구조만 즉시 받고 blob 은 checkout 할 때 lazy fetch. 대부분 workflow 에 shallow 보다 modern + 빠름. Git 2.20+ 부터 가능.

Code

완전 새 프로젝트 — init flow·bash
mkdir new-thing && cd new-thing
git init
echo '.env' >> .gitignore
echo 'node_modules/' >> .gitignore
git add .gitignore
git commit -m "Add starter .gitignore"
git log --oneline    # commit 하나
기존 프로젝트 — clone flow·bash
# SSH (daily dev 에 추천):
git clone git@github.com:org/repo.git

# HTTPS (방화벽 네트워크, CI):
git clone https://github.com/org/repo.git

# 커스텀 폴더 이름:
git clone git@github.com:org/repo.git my-folder

# Shallow (빠름, 전체 history 없음):
git clone --depth 1 https://github.com/org/big-repo.git

# Partial (lazy blob fetch — 대부분 케이스에 shallow 보다 나음):
git clone --filter=blob:none https://github.com/org/big-repo.git

External links

Exercise

Git 안 들어 있는 작은 사이드 프로젝트 폴더 하나 골라 git init, 진짜 .gitignore 쓰고 commit. 다른 머신이나 디렉토리에서 public repo 를 SSH URL 로 (key 있으면) 그리고 HTTPS URL 로 각각 git clone 해봐. 두 케이스에서 git remote -v 가 뭘 보여주는지 비교. init vs clone 언제 쓸지 한 줄로 적어.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.