Git / GitHub 명령어

김정현·2022년 10월 20일
0

기타

목록 보기
5/25
git init: 로컬 레포지토리 생성

git branch: 현재 브랜치 확인
git branch 브랜치명: 브랜치 생성
git branch -d 브랜치명: 브랜치 삭제

git checkout 브랜치명: 브랜치 이동
git checkout -b 브랜치명: 브랜치를 생성 후 이동

git push --set-upstream 레포지토리URL: 
로컬 레포지토리를 URL의 리모트 레포지토리에 연결 후 푸시

git touch: 파일 생성, 수정

git status: 현재 로컬 레포지토리 상태 확인

git add .: 변화가 있는 모든 파일 add
git commit -m "커밋메세지": add된 파일을 로컬 레포지토리에 커밋
git push: 로컬 레포지토리에 commit된 파일을 연결된 리모트 레포지토리에 푸시

git reset --hard + 커밋번호 또는 ^: 해당 commit 취소
리모트 레포지토리 관련 명령어
(여기서 origin은 리모트 레포지토리를 지칭할 이름을 의미하며, 변경해서 사용할 수 있다)

git remote -v: 현재 연결된 리포트 레포지토리 확인
git remote add origin 레포지토리URL: 로컬 레포지토리와 리모트 레포지토리 연결
git remote remove origin: 연결된 리모트 레포지토리 제거
git remote update: 로컬 레포지토리를 연결된 리포트 레포지토리의 상태로 최신화
(리모트 레포지토리의 모든 브랜치의 파일을 pull하여, 
브랜치를 변경하는 것으로 모든 브랜치의 최신 상태에 접근할 수 있게 된다
npm 관련 명령어
⚠️ npm 관련 에러가 발생했을 때, 모듈 재설치로 해결이 안된다면 아래의 명령어를 사용해보자

npm update -g: NPM 전역 패키지를 업데이트

npm캐시 삭제 및 업데이트 명령어:
npm uninstall -g create-react-app
npm i -g npm@latest 
npm cache clean -f 
npx create-react-app@latest my-app --use-npm

npm audit fix: 보안 취약성 제거
npm audit fix --force: 보안 취약성 제거 상위 명령

⚠️ 깃 에러1:

 * branch            develop    -> FETCH_HEAD
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint: 
hint:   git config pull.rebase false  # merge
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.

광범위 하게 발생하는 에러로, 발생하는 경우는 다음과 같다

  1. pull 받을 브랜치와 현재 작업 브랜치의 내용이 많이 차이나는 경우:
    merge하지 않은 main과 같이 초기상태의 브랜치에서
    새로운 브랜치를 분기해준 뒤, pull을 실행하면 정상적으로 pull을 받을 수 있다
    이후 작업 브랜치로 이동하여 merge후 충돌을 처리한다

⚠️깃 에러2:

error: Your local changes to the following files would be overwritten by merge:

여러 명이 함께 사용하는 브랜치를 pull할 때 발생하는 에러로,
에러의 원인은 pull 로 가져오려는 소스와
현재 저장된 코드와 제대로 처리가 되지 않아서 나는 에러이다.

이때 stash 는 현재 디렉토리의 파일을 임시로 백업하고 깨끗한 상태로 돌린다.

git stash 이후 git pull origin master를 할 경우
정상적으로 업데이트 되는 것을 확인 하실 수 있다.


⚠️git ignore가 작동하지 않을 때:

git rm -r --cached .

캐시를 삭제한 뒤, 다시 커밋한다.

profile
개발 공부 블로그

0개의 댓글