[Git 시리즈 4편] GitHub 연동 - push, pull, clone

한국어 버전

로컬 Git 저장소를 GitHub와 연동하여 코드를 클라우드에 저장하고 공유하는 방법을 실습합니다.


이 글에서 할 것

  • GitHub 계정 생성하고 저장소 만들기
  • 로컬 저장소와 GitHub 연결하기
  • 코드 push/pull 하기
  • 저장소 clone 하기

준비물

  • Git이 설치된 터미널
  • GitHub 계정 (없으면 생성 필요)
  • 이전 실습의 my-first-git-project

실습 1: GitHub 계정 생성

GitHub 가입

  1. github.com 접속
  2. Sign up 클릭
  3. 이메일, 비밀번호, 사용자이름 입력
  4. 이메일 인증 완료

실습 2: GitHub 저장소 생성

새 저장소 만들기

  1. GitHub에서 + 버튼 클릭
  2. "New repository" 선택
  3. Repository name: my-first-repo
  4. Public 선택
  5. "Create repository" 클릭

생성 후 화면:

git remote add origin https://github.com/사용자이름/my-first-repo.git
git branch -M main
git push -u origin main

실습 3: 원격 저장소 연결

로컬 프로젝트로 이동

cd ~/my-first-git-project

remote 연결

git remote add origin https://github.com/사용자이름/my-first-repo.git

연결 확인

git remote -v

예상 출력:

origin	https://github.com/사용자이름/my-first-repo.git (fetch)
origin	https://github.com/사용자이름/my-first-repo.git (push)

실습 4: 코드 Push

Push

GitHub에 Push zsh · ~/workspace
Ready. Press Replay to run the scripted session.

GitHub에서 확인

  1. github.com에서 저장소로 이동
  2. README.md 내용 확인
  3. 파일 목록 확인

실습 5: GitHub에서 수정 후 Pull

GitHub에서 파일 수정

  1. GitHub에서 README.md 클릭
  2. 연필 아이콘(✏️) 클릭
  3. 내용 수정:
    # My First Project
    GitHub에서 수정했습니다!
    
  4. "Commit changes..." 버튼 클릭
  5. 커밋 메시지 입력
  6. "Commit changes" 클릭

로컬로 Pull

GitHub에서 Pull zsh · ~/workspace
Ready. Press Replay to run the scripted session.

로컬에서 확인

cat README.md

예상 출력:

# My First Project
GitHub에서 수정했습니다!

실습 6: Clone 실습

새 폴터에서 Clone

cd ~
mkdir test-clone
cd test-clone

Clone

저장소 Clone zsh · ~/workspace
Ready. Press Replay to run the scripted session.

Cloned 프로젝트 확인

cd my-first-repo
ls -la

예상 출력:

total 8
drwxr-xr-x  4 username  staff  128 Mar 13 10:00 .
drwxr-xr-x  3 username  staff   96 Mar 13 09:00 ..
-rw-r--r--  1 username  staff   50 Mar 13 10:00 README.md
-rw-r--r--  1 username  staff   11 Mar 13 10:00 hello.txt

핵심 명령어 정리

명령어 설명
git remote add origin URL 원격 저장소 연결
git remote -v 연결 확인
git push -u origin main 코드 올리기
git pull 코드 받아오기
git clone URL 저장소 복제

실수 대처

"fatal: Authentication failed"

해결:

  • GitHub 사용자이름/비밀번호 확인
  • 비밀번호 대신 Personal Access Token 사용

"rejected: non-fast-forward"

해결:

git pull origin main
git push origin main

"fatal: not a git repository"

해결:

cd 올바른_폴터
git init  # 또는 git clone

실습 완료 체크리스트

  • GitHub 계정 생성
  • GitHub 저장소 생성
  • remote 연결
  • push 성공
  • GitHub에서 파일 수정
  • pull 성공
  • clone 성공

다음 편

👉 Git 시리즈 5편: 브랜치와 .gitignore

💬 댓글

이 글에 대한 의견을 남겨주세요