bsh6226 2024. 9. 16. 14:14

Git 공식문서

https://git-scm.com/docs

 

Git 설치 (MAC)

1. 터미널 실행
2. brew intall git 입력
3. git ‒version 입력해 확인
4. Config 설정 (User Name / User Email 설정)

5.설치완료

Git 초기설정

로컬에서 사용할 Git 사용자 이메일과 이름을 설정한다. 이메일을 세상에 단 한가지만 존재할 수 있기때문에 효과적인 Identification 기호이다. 해당 설정을 바꾸면 git을 통해서 적용되는 commit들에 본인의 email이 tag된다. 

 

GIT config에 이름와 메일 초기설정하기

  • git config : Git에 관한 설정을 추가/변경/삭제하는 명령어
    •  System 설정 파일 : 모든 시스템 사용자에게 적용 (git config --system) ; 컴퓨터 내 모든 사용자에 적용
    • Global 설정 파일 : 한 사용자의 전치 Git Repository에 적용 (git config --global) ; 컴퓨터 내 특정 사용자에 적용
    • Local 설정 파일 : 하나의 Repository에만 적용 (git config --local) ; 프로젝트 별로 적용
      • user.email "email@emial" : 유저의 이메일정보를 정의
      • user.name "name" : 유저의 이름정보를 정의
  • git config --list : config정보를 나열하여 리스트로 출력한다.

 

GIT 초기화

GIT 초기화란 폴더 안의 문서를 Git으로 버전 및 이력관리를 하겠다는 선언이며 localRepository를 만드는 것이다.  Git 초기화 시 폴더 안에 숨김 폴더로 .git 폴더 생성함 (Local Config 등으로 구성). 만약, Git 관리를 삭제하고 싶으면 단순히 .git 폴더를 삭제하면된다. 

 

  • CLI 명령어 : git init, 초기화 할 대상 폴더에서 명령어 (git init) 입력
  • 폴더를 삭제하는 명령어 입력 : rm ‒rf .git

     

 

 

 

 

SSH key 생성하여 key로 Github연동하기

git문서에서 ssh key 공개키 생성하기 방법을 알려주고있다. 

 

https://git-scm.com/book/ko/v2/Git-%EC%84%9C%EB%B2%84-SSH-%EA%B3%B5%EA%B0%9C%ED%82%A4-%EB%A7%8C%EB%93%A4%EA%B8%B0

 

1. CLI : cd ~/.ssh : 홈 디렉토리의 ssh라는 숨김 디렉토리로 이동한다.

2. CLI : ssh-keygen : Mac CLI의 ssh key생성 명령어 실행하여 ID와 PW를 생성한다

3. CLI : cat ssh.pub파일경로 : ssh.pub의 공개키를 확인함

4. Github 접속 후 오른쪽 상단 프로필 클릭 Setting -> SSH and GPg Keys

5. New SSH Key 클릭해 Title과 복사한 Key 입력 후 Add SSH Key 클릭, 파일 내 전문 입력.

 

SSH란?

SSH, which stands for Secure Shell, is a cryptographic network protocol used for securely accessing and managing remote computers and servers over a network, typically the internet. 비대칭키 방식으로 클라이언트와 서버 간의 최초인증을 진행하고 있다. 서버와 클라이언트는 각자의 private key를 가지고 있고 public key를 교환한다. 이 비대칭적 암호는 암호화는 공개키를 통해서, 해독은 비공개키를 통해서 가능하다. 비대칭키 방식으로 최초 인증을 한 후에, 대칭키를 활용하여 서로 통신을 진행한다. 

 

  • Private Key: This is kept secret and should never be shared. It stays on your local machine and is used to decrypt messages encrypted with your public key.
  • Public Key: This key can be shared freely. It is placed on the remote server or service that you want to access.

 

 

 

 

Git 동작원리 및 개념

용어정리

Working Directory : 작업하는 파일이 있는 디렉토리. 작업하고 있는 폴더 자체.
Staging Area : Git에 등록할 (커밋) 파일들이 올라가는 영역. git을 등록하기전에 우선 올려놓는 곳.
Local Repository : 로컬 Git 프로젝트의 메타데이터와 데이터 정보가 저장되는 영역.  여기까지 Local영역.

Remote Repository : Github 등의 서비스를 통한 온라인 상의 저장소. 다른사람들이 코드를 사용하기 위해서는 remote까지 올라가야.

origin : 원격 (Github 등의 온라인 저장소)에 있는 코드

head : 내가지금작업하고있는로컬브랜치
add : Working Directory에서 Staging Area로 등록하다

commit :Add로 등록된 파일들을 한 덩어리로 만들고 메시지 추가해 Staging Area에 등록된 파일을 Local Storage로 등록
Commit Message : commit 시 함께 작성해 저장하는 메시지 (메모)
push : Local Storage에서 변경된 파일들을 Remote Repository로 등록

fetch : Remote Repository의 변경된 파일들을 Local Repository로 전달

merge : Local Repository의 변경사항을 Working Directory로 전달

Branch : 독립적으로 어떤 작업을 따로 진행하기위한 가지

checkout : 여러브랜치가 있는 가운데 현재 사용할 다른 브랜치를 지정

rebase : merge의 경우 각 branch의 history를 별도로 보관하지만 rebase는 각 branch의 history를 하나로 일괄 합친다.

 

Local Repository

파일이나 폴더를 저장하는 곳. Git저장소는 파일 전체를 저장하는 것이아니라 파일에서의 변경정만 이력별로 구분되어 저장. Snapshot (파일이나 폴더를 사진을 찍듯 순간의 상태를 저장한다.)기법을 사용. Local Repository 생성은 해당폴더에서 git init 명령어 입력으로 이루어진다.

 

Remote Repository
파일이 전용 서버(Github)에서 관리되며 여러 사람이 함께 공유

 

Branch

새로운 

 

 

 

Git 사용의 개념

 

Gitflow

https://techblog.woowahan.com/2553/

Commit Message

https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/

 

How to Write Better Git Commit Messages – A Step-By-Step Guide

When first introduced to Git, it's typical for developers to feel uncomfortable with the process. You might feel uncertainty when encountering the Git commit message, unsure how to properly summarize the changes you've made and why you've made them....

www.freecodecamp.org

why care?

  By writing good commits, you are simply future-proofing yourself. You could save yourself and/or coworkers hours of digging around while troubleshooting by providing that helpful description.

when to commit?

 

what to think? 

  • Why have I made these changes?
  • What effect have my changes made?
  • Why was the change needed?
  • What are the changes in reference to?

what to write? : Conventional Commits

  • feat – a new feature is introduced with the changes
  • fix – a bug fix has occurred
  • chore – changes that do not relate to a fix or feature and don't modify src or test files (for example updating dependencies)
  • refactor – refactored code that neither fixes a bug nor adds a feature
  • docs – updates to documentation such as a the README or other markdown files
  • style – changes that do not affect the meaning of the code, likely related to code formatting such as white-space, missing semi-colons, and so on.
  • test – including new or correcting previous tests
  • perf – performance improvements
  • ci – continuous integration related
  • build – changes that affect the build system or external dependencies
  • revert – reverts a previous commit

 

 

 

CLI에서의 Git 사용

 

GUI툴을 다운로드하여 사용하면 모든 것을 CLI로 운영할 필요가 없다. 더 직관적이고 이용이 편리하다. 다만, 서버컴퓨터를 다룰때는 CLI만 사용할 수 있어서 간단한 CLI는 인지하고 있어야한다.

 

 

Intellij 에서의 Git 사용

 

Visual Cue

새로 추가후 VCS에 미등록 클래스 : DIR에서 붉은 색으로 표기

기존 클래스에 변화가 있음 : DIR에서 파란 색으로 표기

새로 추가된 코드라인 : 코드라인에 초록줄로 표기 (변경사항 전부 원복 가능)

 

코드라인우클릭 - Annotate with gitBlame : 각 코드별로 누가 언제 수정했는지 표기됨

Annotation with gitBlame - 더블클릭 : 각 코드가 언제 어떤 코드와 함께 Push되었는지 확인가능

 

Clone : file - new - projectFromVersionControl - URL 입력

 

GitHub에서의 Git 사용

Branch Merge : Branch가 생겼을 때 Pull Request를 통해서 변경점을 확인한 후에 두개의 Branch를 하나로 합치는 방법이 권장된다.

 

 

GitHub에서의 기타기능

Pull Request template : pull_request_template.md라는 파일을 생성하면 pull request를 생성할때마다 해당 포맷을 사용할 수 있게 해준다.

 

github와 slack 연동

관련해서 한번 찾아서 전체적인 flow를 보시면 이해하기 더 쉬우실거에요