Skip to content

Git 주의사항 #1

@saeyeonn

Description

@saeyeonn

!!!! 작업하기 전에 항상 개인 브랜치에 있는지 + pull 했는지 확인하고 시작 !!!!


1. git remote 등록

git remote add origin <repo url>
# <repo url>을 origin 이라고 이름 붙여 추가한다는 의미


2. git pull = git fetch + git merge

git pull origin main
# Remote repository commit과 Local repository를 동기화하고 Merge (중요!!!)

3. 개인별 브랜치

git checkout -b <branch name>
# 해당 이름의 branch 분기하여 생성 + 이동

git checkout <branch name>
# 이미 생성되어 있는 해당 branch로 이동

4. 실수로 다른 브랜치에서 작업했다면

git stash
# 커밋하지 않고 해야 함
# 스테이지 되지 않은 파일을 임시로 백업

git stash save <backup name>

git stash list
# 백업 목록 확인


4. git add

git add .
# 변경된 전체 파일 반영

git add <file>
# 해당 파일만 반영

5. git commit

git commit -m "<commit message>"
# README.md -> Git -> Commit message convention 확인한 후 꼭 지키기

6. git push

git push origin <branch name>
# 해당 레포지토리에서는 본인 이름의 브랜치에 있는지 잘 확인하기

Push하고 Pull Request 생성해야함!!


7. git fetch / status

git fetch
# Remote Repository Branch & Commit을 Local Repository와 동기화 (merge X)

git status
# 원격 저장소의 상태 확인

  1. git reset
git reset --soft HEAD^
# 헤드를 옮겨 마지막 커밋을 취소
# --soft : 작업 디렉토리와 인덱스를 보존해 파일이 스테이지된 상태 유지하도록 함

git reset --hard <commit hash>
# 돌아가고 싶은 버전의 커밋 해시를 통해 특정 커밋으로 옮김
# --head : 작업 디렉토리, 헤드, 인덱스, 모두 변경

git reset <file>
# File unstaging
# 파일명 명시하지 않으면 모든 파일을 언스테이징함

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions