프론트엔드 개발자의 개발 놀이터

Git 명령어 정리 본문

git

Git 명령어 정리

프론트포텐 2024. 2. 2. 11:30
반응형

 

git 저장소 초기화 (loacl storage에 git 폴더 생성)

git init

 

git 상태 확인

git status

 

변경사항 확인

git diff

 

변경된 파일명의 내용을 추가

git add 파일명

 

변경된 내용 모두 추가

git add .

 

추가된 모든 내용들을 untracked 상태로 변경

git rm --cached *

 

commit(메모)과 함께 변경내용을 확정

git commit -m '메모'

 

입력된 이름과 주소로 원격 저장소를 추가 (초기 상태의 원격 저장소 별칭은 origin)

git remote add 이름 주소

git remote add origin https://github.com...

 

원격저장소 삭제

git remote remove 이름

git remote remove origin

 

원격저장소의 이름 변경

git remote rename 이름 바꿀이름

git remote rename origin dev

 

현재 저장한 원격저장소 목록 표시

git remote -v

 

-m flag를 통해 master branch를 main branch로 이름 변경

git branch -m master main

 

로컬 레포지토리의 변경 사항을 github branch로 push

git push origin main

 

데이터 갱신

git pull origin main

 

github에서 데이터 받아오기

git clone 주소

git clone https://github.com...

# 특정 브랜치 불러오기
git clone -b branch명 https://github.com...

 

브랜치 확인

git branch

 

브랜치 생성

git branch 브랜치명

git branch dev

 

생성한 브랜치로 전환

git checkout 브랜치명

git checkout dev

 

브랜치 삭제

git branch -d 브랜치명

 

git merge

git merge 브랜치명

# main 브랜치에 dev 브랜치를 병합하고 싶을 경우
git checkout main
git merge dev
# ...add, commit, push

# 충돌 방지
git checkout dev
git pull origin dev
git checkout main
git merge dev
# ...add, commit, push

 

git 삭제

rm -rf .git

 

git 버전확인

git --version

 

git 구성 확인

git config

 

git commit log 확인

git log

# 스페이스바를 누르면 변경 이력이 하나씩 보여짐
git log -p

 

git 설정 확인

git config --global --list

 

.gitconfig 파일 열기

git config --global -e

 

.gitconfig 파일을 IDE(VSCode)를 통해서 열기

git config --global core.editor "code --wait"

 

이름 설정

 git config --global user.name “이름”

 

메일주소 설정

git config --global user.email “메일주소”

 

이름 확인

git config user.name

 

메일주소 확인

git config user.email

 

명령어 별명(단축어) 설정

git config --global alias.st status