git은 분산형 버전 관리 소프트웨어로, 소스 버전 관리를 협업자들의 각기 다른 (분산된) local repositary에 업데이트 하고, github라는 remote repositary(Github)에서 공유하여 협업을 하게 업데이트 해주는 소프트웨어이다.
기본적으로 명령 프롬프트 상에서 명령어 기반으로 원하는 작업을 진행할 수 있다.
workspace - stage - local repositary - remote repositary 사이에서의 동작을 진행
명령어 관련 공식 reference
init -> 해당 디렉터리 상에 git 저장소 생성, .git 폴더가 만들어짐
clone -> workspace에 url(원격저장소, 로컬저장소)의 모든 내용을 복제, 디렉터리 상 기존 존재하던 파일은 제거
pull -> 원경저장소의 변경사항을 workspace에 불러오기 (pull없이는 push를 할 수 없음, workspace에서 작업하던 내용은 유지)
git pull --all
git pull [원격저장소명] [브랜치]
fetch -> 원격저장소의 변경사항을 local repositary에 불러와 확인하기 (pull or merge 할 지 말지 정할 수 있음)
git fetch -- all
git fetch origin
remote -> 원격저장소 관리
# local 저장소에 연결된 원격저장소 확인
git remote
# 원격저장소를 local저장소에 추가
git remote add [별칭] [원격저장소주소]
# 원격저장소 삭제
git remote rm [원격저장소 이름]
merge -> 현재 브랜치를 특정브랜치와 병합
#master branch를 현재브랜치로 merge
# 'master': 최초 repository 생성 후 commit하면 자동으로 생기는 branch
git merge master
현재 local repositary의 상태
변경점 또는 변경사항을 workspace에서 stage에 추가 -> add
파일을 삭제 또는 stage에서 제거 -> rm
# 모든 변경점 추가
git add -A
# 현 디렉터리 상 모든 파일에 변경점 추가
git add .
# 특정 파일만 추가
git add sample.txt
# 파일을 제거
git rm sample.txt
# 파일을 stage에서 제거
git rm -cached sample.txt
commit -> 변경점을 저장 (stage에서 local로)
# message와 함께 저장
git commit -m "msg"
# 모든 변경점 저장
git commit -a
log -> commit 내용 확인
git log --all
reset -> commit 취소
# soft -> stage로, HEAD^ -> 최신 COMMIT
git reset --soft HEAD^
# mixed -> unstaged로, local 변경사항은 유지
git reset --mixed HEAD^
# hard -> unstaged, local 변경점도 제거
git reset --hard HEAD^
revert -> 지정한 commit으로 되돌리고 commit
git revert "commit hash 또는 태그명"
restore -> unstaged 된 또는 staged 된 변경점을 복구
git restore "filename"
git restore staged "filename"
clean -> untracked된 파일을 제거
# 파일만 제거
git clean -f
# 디렉터리도 제거
git clean -f -d
# gitignore 설정 파일도 제거
git clean -f -d -x
# 원격저장소에 특정브랜치 적용
git push [원격저장소명] [브랜치명]
# 전체 브랜치 확인
git branch
# 새로운 브랜치 생성
git branch "name"
# 해당 브랜치로 이동
git checkout [브랜치이름]
# 해당 브랜치 삭제
git branch -d [브랜치이름]
https://urbanbase.github.io/dev/2021/01/15/GitCommand.html
https://velog.io/@jameskoo0503/Github-basics