Git

기본 & 자주 사용하는 명령어

git repository 생성

git init

repository 복사

git clone <repo>
# git clone https://github.com/hve4638/hve4638.github.io

기록 추가 (add, 스테이지)

# 전체 스테이지
git add .

커밋 (commit)

git commit -m "message"

원격 저장소 업로드 (push)

git push <remote> <branch>
# git push origin main

Branch 관련 명령어

branch 확인

git checkout

branch 이동

git checkout <branch>

branch 생성후 이동

# 현재 branch에서 새 branch 생성
git checkout -b <new branch>

# 특정 branch에서 새 branch 생성
git checkout -b <new branch> <base branch>

커밋 되돌리기

reset, revert 차이?

reset은 commit 히스토리를 삭제한다

revert은 되돌리는 기록을 남긴다.

reset

# 돌아간 커밋 이후의 변경 이력을 삭제
git reset --hard <commit>

# WIP
git reset --mixed <commit>

# WIP
git reset --soft <commit>

revert

# WIP
git revert <commit>

응용

커밋후 푸시

git add .
git commit -m "refactor"
git push origin main

main branch에서 dev branch를 생성해 분리

git checkout main
git checkout -b dev

dev branch의 변경사항을 main branch와 병합

git checkout main
git merge dev
git push origin main