git을 초기화했으니 그 다음은 로컬에서 git에 push 할 파일을 만들 차례이다.
그 전에 git의 workflow를 간단히 이해하고 넘어가자.
Git 의 세 가지 구역
1) working directory
맨 처음 파일을 생성작업하는 곳
- untracked : 새로 만들어진 파일 / 기존의 파일에서 git이 초기화
- tracked : git이 이미 알고 있는 파일
- unmodified : tracked 된 파일 중에서 수정이 되지 않은 파일
- modified : tracked 된 파일 중에서 수정이 된 파일 (수정이 된 파일만 staging area로 옮겨갈 수 있다.)
2) staging area
어느정도 작업을 한 후, 파일들을 옮겨놓는 곳
3) .git directory
version 의 history를 가지고 있는 곳
working directory 에서 파일을 수정하다가 어느정도 다듬어지면
git add
명령어를 이용하여 staging area로 옮긴다.
또한
git commit
명령어를 사용하여 staging area에 있는 파일을 .git directory로 옮길 수 있다. 그리고 이 파일들은 git history에 저장된다.
git 에 저장된 파일들은
git checkout
명령어를 통해 원하는 구역으로 옮길 수 있다.
remote 환경으로 파일을 옮기기 (Github를 사용하는 이유)
저장된 git history는 Local에만 저장되어 있는 상태이기 때문에
Github와 같은 server(remote 저장소)에 push 라는 명령어를 이용하여 업로드 해놓는다.
Local에만 저장되어있는 경우, 컴퓨터가 망가졌거나 파일이 손실 되었을 때 저장해 둔 history가 모두 날아갈 수 있기 때문이다.
만약 server 에서 local로 파일을 다시 옮기고 싶다면 pull 이나 fetch 명령어를 이용하는데, pull 과 fetch 의 차이점은 가져온 소스를 merge 하느냐 안하느냐의 차이이다.
원격 저장소의 소스를 merge 하여 가져오고 싶다면 pull 명령어를,
소스만 가져오고 싶다면 fetch 명령어를 사용하면 되겠다.
전체적인 흐름도
+) 참고
git의 전체적인 workflow를 다룬 3분짜리 영상이다.
git의 흐름, 또는 branch의 역할에 대해 궁금하다면 도움이 될 것 같다.
https://www.youtube.com/watch?v=1SXpE08hvGs
'✏ git & github' 카테고리의 다른 글
[git] git 초기화 및 삭제하기 (git 시작하기) (0) | 2024.06.28 |
---|