Git
- 개발자의 코드를 효율적으로 관리하기 위해서 개발된 ‘분산형 버전 관리 시스템’
- 버전 관리뿐만 아니라 회사에서 협업을 할 때도 굉장히 유용
Github
- Git Repository를 관리할 수 있는 클라우드 기반 서비스
- Github은 내 컴퓨터에서 Git으로 관리하는 프로젝트를 올려둘 수 있는 사이트
사진 : https://www.nagarelab.com/en/3073
용어 및 명령어
Git Repository : Git으로 관리되는 폴더
Remote Repository : 원격 저장소, 작업한 코드를 공유하려면 Remote Repository
Local Repository : 로컬 저장소, 작업할 때는 Local Repository
Contribute : 누구나 자유롭게 해당 기능을 추가하고 개선할 수 있는 오픈소스
- git init : 내 컴퓨터에서 만든 디렉토리를 Git의 관리하의 Local Repo.로 만듦
- git remote add origin <Repo. 주소> : Local Repo. 를 Remote Repo. 에 연결
- git remote add <상대이름> <Repo. 주소> : Local Repo. 를 상대방의 Remote Repo. 에 연결
- git remote -v : 현재의 Local Repository와 연결된 모든 Remote Repository 목록을 확인
- (github site)Fork : 상대 Remote Repo. 의 파일을 나의 Remote Repo.으로 복사
- git clone <Repo. 주소> : 나의 Remote Repo. 의 파일을 Local Repo.으로 복사
- git add <파일명> : 파일(unstaged)을 staging area로 이동
- git add . : 모든 파일(unstaged)을 한 번에 이동
- git rm <filename> : 파일을 Local과 Remote 모두에서 삭제 *삭제한 시점에서 commit 후 push 해야함
- git rm --cashed <filename> : 파일을 Remote 에서만 삭제 *삭제한 시점에서 commit 후 push 해야함
- git status : staging area 상태 확인
- git restore <파일명> : commit 되지 않은 파일의 변경 사항을 폐기
- git commit : 파일을 복사해서 나의 Local Repo. 에 보존
- git commit -m 'coment' : 변경사항 coment 작성 및 commit
- git reset HEAD^ : 아직 Remote Repo. 에 업로드되지 않고 Local Repo. 에만 commit 해 놓은 상태에서 commit 취소
- git push <name> <branch> : Local Repo.에 저장된 commit들을 나의 Remote Repo.으로 업로드
- git pull <name> <branch> : Remote Repo.에서 변경 사항이 있을 때 Local Repo.으로 가져오기
- git log : 현재까지 commit 된 로그들을 터미널 창에서 확인
- (github site)pull request(PR) : 내가 Remote Repo. 에 Push 해 놓은 변경 사항을 함께 작업하는 다른 사람들에게 알리는 것
branch : 하나의 commit과 그 부모 commit들을 포함하는 작업 내역
Head : HEAD는 현재 체크아웃된 commit을 가리킵니다.
- git branch : Local branch의 정보를 보여준다.
- git branch <branch> : branch 생성
- git branch -v : Local branch의 정보를 마지막 commit 내역과 함께 보여준다.
- git branch -r : Remote branch의 정보를 보여준다.
- git branch -a : Local/Remote branch의 정보를 모두 보여준다.
- git branch -d <branch> : branch 삭제. -D 옵션은 강제 삭제
- git branch <–merged | –no-merged> : merge 된 branch를 표시 | merge 되지 않은 branch를 표시
- git merge <branch> : branch 병합
- git checkout <branch> : branch로 이동
- git checkout -b <branch> : branch로 생성과 동시에 이동
- git branch -m <변경 전 branch> <변경 후 branch> : -M 옵션은 동일한 이름의 branch가 있더라도 덮어쓰기
혼자 할 때 작업 흐름
- 상대 Remote Repo.에서 Fork 하여 내 Remote Repo.로 복사한다.
- 수정을 위하여 내 Remote Repo. 에서 clone 하여 Local Repo.로 가져온다.
- 수정된 파일(unstaged)을 add 하여 Staging area(staged)로 이동시킨다.
- staged 파일을 commit 하여 Local Repo.로 이동시킨다.
- Local Repo. 에서 push 하여 내 Remote Repo.로 이동시킨다.
- Remote Repo.에 pull request를 보내 수정된 파일을 업로드한다.
함께 작업 흐름
- git remote add <name> : Local Repo. 를 상대방의 Remote Repo. 에 연결
- git pull <name> <branch> : 상대 Remote Repo. 에 있는 작업물을 Local Repo.로 가져오기. 자동으로 병합(merge)된다.
- 이후 흐름은 혼자 작업 흐름과 동일
상대와 동일한 라인을 수정한 파일이 있어서 Automatic merge에 실패하게 되고 충돌이 발생했을 때
- git status로 충돌 파일 확인 및 수정
- git add로 staging area에 파일 추가
- Merge commit은 자동으로 Commit 메시지가 생성되고, git commit 명령어로 자동으로 생성된 commit 메시지를 남긴다.
- Remote Repository에 Push 한다면 Merge branch ‘master’ of 라는 commit 메시지가 기록된다.
'Git' 카테고리의 다른 글
[Git] Git flow (0) | 2022.10.21 |
---|---|
[Git] Git branch 다루기 (0) | 2022.10.21 |
[Git] GitHub 이슈, 마일스톤, 프로젝트 생성 및 연결 (0) | 2022.10.21 |
[Git] git commit 메세지 컨벤션 (0) | 2022.10.20 |