git 뿌시기!!

Yuzu·2023년 1월 29일
0

git 은...

  • 프로젝트의 버전 관리를 도와주는 시스템
  • version control system (VCS)
    version: 이전과 약간씩 다른 변화(수정, 개선)들을 구분하는 표시

Github 은...

  • git을 이용해 버전 관리를 한 프로젝트들의 저장소, 호스팅 서비스

git 명령어

  1. git init
    첫 세팅을 하기 위한 명령어
    git 저장소 생성, 버전 관리를 위한 정보 생성
    프로젝트를 empty git repository로 만들어준다.

  2. git status
    디렉토리에서 일어나고 있는 git 상태 확인

  3. git add
    수정한 파일의 이력을 남길 준비를 하는 명령어
    git add .
    git add 파일이름

  4. git commit
    수정한 파일의 이력을 남기는 명령어
    git commit -m "commit msg"

  5. git log
    commit 이력 확인

  6. git push
    commit한 코드를 github repository로 밀어넣겠다.
    git push origin 브런치이름

  7. git clone
    기존 repository를 내 local로 가져오는 명령어
    git clone repositoryUrl

  8. git branch
    전체 브랜치 확인 or 독립적으로 개발할 수 있는 공간을 만드는 명령어
    git branch 브랜치이름

  9. git checkout
    다른 브랜치로 이동할 때 사용하는 명령어
    git checkout 브랜치이름
    git checkout -b 브랜치이름 : 브랜치 생성과 동시에 이동

  10. git pull
    github에 있는 특정 브랜치의 코드를 local로 가져올 때 사용하는 명령어
    git pull origin 브랜치이름(주로 master)

  11. git merge
    local에서 현재 브랜치의 코드와 특정 브랜치의 코드를 합칠 때 사용
    git merge 브랜치이름

상황별 git 사용

1. github에 코드가 저장되어 있는 repository가 존재

cd 폴더이름 //local 폴더로 이동
git clone repositoryUrl // 프로젝트 폴더를 remote->local로 클론
cd 프로젝트폴더 // 생성된 프로젝트 폴더로 이동
git branch 브랜치이름 //branch 생성
git checkout 브랜치이름 //local master-> branch 이동
코드 작성...
git add .
git commit -m "commit msg"
git push origin 브랜치이름 //local branch 작업내역 remote로 올리기
GitHub 상에서 PR등록 및 merge 완료
git checkout master //local branch -> master로 이동
git pull origin master // remote master -> local master로 가져오기 (local master의 최신화)

2. github상에 비어있는 repository에 초기세팅된 코드를 올려야함

cd 폴더이름 //local 폴더로 이동
npx create-react-app 프로젝트폴더 // CRA를 통해서 프로젝트 생성
cd 프로젝트폴더 // 생성된 프로젝트 폴더로 이동
초기세팅 작업
npm install react-router-dom
npm install sass
npm install styled-components styled-reset
npm package 설치 (eslint, prettier 등)
git init // git repository 생성
git add .
git commit -m "commit msg"
git remote add origin repositoryUrl // local repository를 remote origin에 추가(연결)
git push origin master // master 작업내역을 remote에 올리기

profile
냐하

0개의 댓글