Git 로컬 작업 폴더 원격 저장소에 연결하기 (HTTPS 방식 기준)


1. 로컬 Git 저장소 초기화 및 원격 연결

1.1 Git 초기화

git init

1.2 원격 저장소 연결

git remote add origin https://github.com/사용자명/저장소명.git

2. GitHub Personal Access Token(PAT) 사용

GitHub는 2021년부터 비밀번호 인증을 중단하고 토큰(PAT) 인증 방식만 허용함


2.1 토큰 발급 방법

  1. GitHub 로그인
  2. 우측 상단 → Settings > Developer settings > Personal access tokens
  3. Tokens (classic)Generate new token
  4. repo, workflow 등의 권한 선택 후 생성

2.2 토큰 저장 방법

방법 1: Git 사용 시 직접 입력

git push origin main

방법 2: 캐시 저장

git config --global credential.helper store

3. Git 기본 명령어 흐름

3.1 기존 원격 저장소 내용 가져오기 (선택)

git pull origin main --allow-unrelated-histories

3.2 작업 파일 스테이징

git add .

3.3 커밋

git commit -m "커밋 메시지"

3.4 원격 저장소에 푸시

git push -u origin main

✅ 최초 연결시

git init
git remote add origin https://github.com/username/repo.git
git pull origin main --allow-unrelated-histories
git add .
git commit -m "초기 커밋"
git push -u origin main




Revision #5
Created 20 May 2025 23:47:08 by Dain
Updated 21 May 2025 02:03:32 by Dain