vscode에서 github 커밋하기
1. 리액트 프로젝트를 vite로 만들었고, vscode로 해당 프로젝트를 열었음
2. github에 새로운 빈 리파지토리를 만든 상태임
3. 이제 vscode를 이용해서 해당 프로젝트를 github에 커밋하는 방법
1. Git 초기화
VSCode 터미널에서 아래 명령어 입력
터미널이 안보이면 상단메뉴 [터미널] - [새 터미널] 클릭
git init
2. .gitignore 파일 확인
루트 폴더에 .gitignore 파일이 없다면, 생성하고 아래 내용을 추가하기
node_modules/
dist/
.env
dist/
.env
3. 커밋할 파일 추가
git add .
4. 최초 커밋
git commit -m "Initial commit"
5. GitHub 원격 저장소 연결
GitHub에서 만든 빈 저장소 주소를 복사해서 아래처럼 입력하기
ex) https://github.com/username/my-react-app.git
git remote add origin https://github.com/username/my-react-app.git
6. 원격 저장소로 푸시
git branch -M main
git push -u origin main
git push -u origin main
이때 만약 아래와 같은 오류가 발생한다면
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/username/my-react-app.git/'
fatal: Authentication failed for 'https://github.com/username/my-react-app.git/'
다시 한번 git push -u origin main 를 입력하고 잠시 기다리면
[Connect to GitHub] 창이 뜨면서 GitHub Sign in 할 수 있는 화면이 나온다.
[Sign in with your browser] 버튼을 클릭하고 브라우저에서 GitHub에 로그인하고, 다시 vscode로 돌아와서 다시 작업해보면 된다.
이제 깃헙에서 해당 리파지토리에 접속해보면 커밋되어 있는 프로젝트를 확인할 수 있다.