github에 repo clone 하지 않고 바로 로컬에서 첫 소스 코드 업로드 방법


보통 github에 소스코드 업로드시 아래와 같은 방법으로 진행 합니다

github에 repo 생성 → 로컬 PC에서 해당 remote git clone → repo 폴더에 소스 코드 이동/복사 → git add → git commit → git push

아래에 설명된 방법은 clone 단계를 거치지 않고 바로 업로드 하는 방법 입니다.


작업 방법

# 소스코드가 있는 폴더로 이동
cd {소스코드가 위치한 폴더}

# git init
git init

# repo 별로 git 사용자, 이메일 정보 설정 (해당 repo만 적용되는 설정)
git config user.name "{git commit history에 노출될 이름}"
git config user.email {github email 주소}

# 설정된 사용자, 이메일 정보 확인
git config user.name
git config user.email

# 소스코드 add all
git add .

# initial commit
git commit -m "Initial Commit"

# master -> main 으로 브런치 명 변경 (master 브런치에서 수행)
git branch -M main

# remote repo 주소 등록
git remote add origin https://github.com/{github id}/{github repo name}.git

# remote repo push
git push -u origin main

# 번외 gitignore 에 등록된 파일이 업로드 되었을 경우 원격에서만 삭제 하는법
git rm --cached -r .idea
git rm --cached -r gradle/wrapper