Git 로컬 저장소 생성부터 Github 업로드까지 요약
1, Git으로 버전관리 하고싶은 폴더로 이동 후 Git Bash here
2. git init으로 repository(로컬)생성
3. 사용자 정보설정
git config user.name "내 깃허브 아이디"
git config user.email "내 깃허브 이메일"
** (깃허브 정보랑 다르게 적으면 푸시할때 내 계정에 contribution 안찍힘!!) **
4. git add .
5. git commit -m "Create project"
6. Github 사이트에서 빈 repository(리모트) 생성
7. "…or push an existing repository from the command line" 아래 코드 그대로 복사
git bash에 붙여넣기 (shiht+insert)
"
git remote add origin [해당 Git repo 주소]
git branch -M main
git push -u origin main
"
★ git branch -M main 의 의미?
Github는 master branch를 기본으로 사용했었으나, 최근에 main branch를 기본으로 사용하는 것으로 수정되었다.
하지만, 로컬의 git bash는 처음 설정을 할 때, master branch를 기본으로 생성한다.
때문에 로컬과 원격 branch를 맞춰주기 위해 branch 이름을 바꿔주는 것
git branch -m / --move = Move/rename a branch and the corresponding reflog.
* reflog = reference log (HEAD 변경 히스토리)
git branch -f / --force = Reset <branchname> to <startpoint>, even if <branchname> exists already. Without -f, git branch refuses to change an existing branch. ~~
(= branch 이름를 강제로 변경한다. 이름이 이미 존재하더라도 변경한다.)
git branch -M = Shortcut for --move --force.
이거 하나 몰라가지고 어제 엄청 해맸다. 나는 원격 저장소에 있던 main branch로 push를 하려고 하는데 자꾸 뜬금없는 master branch를 하나 만들고 거기로 올라가서 아니 이게 왜이런가 싶었는데 이런 사유가 있었던 것이다.

