Programing/Git

[Git] Github 프로젝트 생성하고 파일 업로드 하기

hye3193 2024. 2. 23. 18:16

1. 깃허브에 repository(원격 저장소) 만들기

2. 로컬 저장소 만들기

프로젝트 폴더에서 Git bash here 누르고

$ git init

명령어 입력

 

3. repository와 로컬 저장소 연결

$ git remote add origin [URL]

URL은 레포지토리에서 Code 버튼 누르면 뜨는 HTTPS 주소다

* SSH로 연결시키려면 따로 키 발급이 필요

 

// 연결된 repository 변경
$ git remote set-url origin [URL]

// 연결된 repository 삭제
$ git remote rm origin

// 연결된 repository 확인
$ git remote -v

 

4. 파일 올리기

$ git add .
$ git commit -m "commit message"
$ git push origin [branch]

add로 파일을 올리고, commit하고, push한다

 

+) 브랜치명

깃허브의 기본 branch명이 main이기 때문에, 현재 기본 브랜치명이 master로 되어 있다면 이를 변경해준다

$ git branch -m master main

 

branch 기본 이름을 전부 main으로 변경시키기 위해서는 아래와 같이 명령어를 입력해준다

$ git config --global init.defaultBranch main