Fork
: 다른 원격 저장소(Remote Repository)의 코드를 내 원격 저장소(Remote Repository)로 가지고 오는 작업
Clone
: 아직 연결되지 않은 내 원격 저장소의 코드를 내 컴퓨터(Local Repository)로 가져오는 것
Pull
: Remote Repository에서 내 컴퓨터(Local Repository)로 가져오는 것
Pull request(PR)
: Remote Repository에 Push 해 놓은 코드 변경사항에 대해 반영 여부를 요청하는 것
Staging Area
: commit 이전 파일들이 머무는 곳.
pull
과 clone
의 차이pull
은 이미 연결된 Remote Repository에서 업데이트본을 가져올 때 사용
clone
은 연결되지 않은 Remote Repository에서 소스를 가져올 때 사용하며, 자동으로 연결된다.
git init .
: 현재 디렉토리를 git에게 버전관리 시키는것 (Local Repository로 선언)
git add (filename)
: 해당 파일을 Staging Area에 올리기
git add .
: 현재 디렉토리의 모든 파일들을 올리기
git status
: 현재 git의 상태를 보여줌. (버전제출 될 파일 등 working tree status)
git commit -m "메시지"
: 버전 제출
(버전을 제출하면 해당파일은 repository로 저장되고, staging area에서 삭제된다.)
git commit -am "메시지"
: add와 commit을 한번에 하기
(하지만 untracked file은 자동으로 add가 되지 않음. 최초 한번은 add가 되어 tracked가 되어야 함)
git commit --ammend
: 이미 commit한 경우에도 내용수정 가능
git log
: 버전(commit)기록 보기. (나갈때는 q)
git log --stat
: 버전 변경사항 세부내용 확인
git log -p
git diff
: 버전을 생성하기 전에, 이전 버전과 달라진 부분을 보여줌(제출 전 검토)
git restore [파일명]
: commit 되지 않은 Local Repository의 변경사항을 폐기
commit 옵션
아직 Remote Repository에 업로드되지 않고 Local Repository에만 commit 해 놓은 기록이라면 reset
명령어를 통해서 commit 을 취소할 수 있다.
git reset HEAD^
: 가장 최신의 commit 을 취소할 수 있다. 여기서^
는 가장 최근으로부터 취소할 commit의 횟수를 뜻한다.git reset --hard
: 파일 내용이 완전히 삭제되어 working directory, stage 어디에도 보이지 않는다.git reset --soft
: 파일 내용이 유지되어 stage에 남아있게 된다.
git remote add <Repository 이름> <Repository 주소>
: Local Repository를 Remote Repository와 연결한다.
git remote -v
: 현재의 Local Repository와 연결된 모든 Remote Repository 목록을 확인할 수 있다.
git push <name> <branch>
: Local Repository에서 Remote Repository로 업로드 하는 것
git push origin main / git push pair dev 등 git push 뒤에 따라오는 명령어는 상황에 따라 변경할 수 있다.
예를 들어, 리모트에 있는 origin의 master 브랜치에 Local Repository의 변경사항을 업로드하기 위해서는 git push origin master이라고 입력한다.
git pull <name> <branch>
: 나의 또는 다른 사람의 Remote Repository에서 나의 Local Repository로 가져온다.
일반적으로 Pull을 하면 자동으로 병합(merge)되는데, 같은 파일의 같은 부분의, 내용이 다른 두 branch를 병합하는 경우 충돌(conflict)이 발생한다.
이 경우 수정 후 다시 commit이 필요하다.