Git 사용법
Devops

Git 사용법

1. Git과 Github

- Git : Local으로 개인이 작업하는 공간

- 작업 dir에서 git init 명령어를 통해 Git dir로 변경

- Github : Remote로 협업의 공간

- 대표적으로 Github를 사용하면 다른 사이트를 사용할 수도 있음

 

GitHub: Where the world builds software

GitHub is where over 56 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and feat...

github.com

2. Local과 Remote

Local Working directory 실제 작업을 하는 directory
Staging area(Index) 준비가 된 파일을 옮기는 directory로 파일들이 추적 됨
git directory(git repository) 스냅샷되어 version이 기록 됨
Remote git directory(git repository) 협업 directory로 스냅샷되어 version이 기록 됨

 

- Git 상태

Untracked Working directoy에만 있는 파일, 일반적으로 .gitignore에 Untracked할 파일 기입
Tracked Staged Working directoy에서 Staging area로 이동된 파일
Modified Staging area에 있는 파일이 수정될 경우 Modified로 상태 변경
Unmodified Working directoy에서 Git directory로 이동 후 Staged에서 Unmodified로 상태 변경

3. git add

- Working directory에서 Staging are로 이동

- Untracked에서 Tracked로 상태 변경

 

- git add * vs git add .

- 특정 파일 delete한 후 git add * 하게 되면 deleted 파일은 Staging area까지 반영되지 않음

- 특정 파일 delete한 후 git add . 하게 되면 deleted 파일은 Staging area까지 반영 됨

4. git commit

- Staging are에서 Git directory(Local)로 이동

5. git push

- Git directory(Local)에서 Git directory(Remote)로 이동

- git push [Gite directory(Remote)] [Branch]

6. git remote

- Git directory(Remote)를  Origin으로 세팅

7. git branch

- 신규 branch 생성

- branch 변경

8. git merge

- branch는 독립적으로 동작(commit까지 완료)

- local에서 branch 병합(test branch를 master에 병합)

- remote에서 branch 병합(test branch를 master에 pull request(PR) 후 병합)

9. git reset

- 이력이 삭제되며 특정 commit으로 되돌아감

- soft(staged상태로 되돌아감)

- hard(이후 commit 기록이 사라짐)

- mixed(untracked 상태로 되돌아감)

10. git revert

- reset과 동일하지만 이력은 삭제되지 않음

11. git fetch

- remote에서 업데이트된 것들을 가져옴

- diff를 통해 remote에서 가져온 것과 local에서 작업한 것을 비교 후 merge

12. git clone

- remote git directory를 가져옴

13. git pull

- remote에서 업데이트된 것들을 가져옴

- merge까지 해줘 바로 확인 가능

14. git checkout

- 원하는 branch의 이전 commit을 다녀올 수 있음

15. HEAD

- 현재 branch가 위치한 부분

ex ) HEAD~1(1생략 가능) or ^ : 바로 전 commit 나타냄

ex ) HEAD~2 or ^^ : 바로 전전 commit을 나타냄

'Devops' 카테고리의 다른 글

terraform 버전 관리 : tfenv  (0) 2021.10.03
Config 자동화 툴(puppet, chef, salt, ansible)  (0) 2021.04.13
Terraform 사용법  (0) 2021.03.20
AWS CDK 사용법  (0) 2021.03.20
Infrastructure as Code(IaC)  (0) 2021.03.20