git 명령어 정리
date
Aug 9, 2024
slug
git-command-summary
author
status
Public
tags
Git
summary
git 명령어 정리
type
Post
thumbnail
category
✍️ Study
updatedAt
Jan 24, 2025 06:18 AM
Git 명령어 총정리
Git을 사용하다 보면 주로
add, commit, push, pull, clone, fetch 등의 명령어를 사용하게 됩니다. 하지만 Git에는 이 외에도 다양한 명령어들이 있습니다. 이번 포스팅에서는 Git의 기본적인 설정 및 초기화, 사용법, 브랜치 관리, 이력 조회, 원격 저장소 관리 등의 명령어들을 정리해보겠습니다.1. 설정 및 초기화 명령어
전역 설정 git config --global user.name "Your name" git config --global user.email "Your email address" 저장소별 설정 git config user.name "Your name" git config user.email "Your email address" 설정 정보 조회 git config --global --list git config --list 저장소 생성 및 복제 git init git clone <저장소 url> git remote add <원격 저장소> <저장소 url>
2. 기본적인 사용법 명령어
파일 추가 및 커밋 git add <파일> git add . git add * git add -p [<파일> ...] git commit -m "<메시지>" git commit -m "<메시지>" --amend git commit -C HEAD --amend git commit --date "1 day ago" -m "<메시지>" 변경 사항 되돌리기 git checkout HEAD <파일> ... git reset HEAD <파일> ...
3. 브랜치 관리 명령어
브랜치 목록 보기 git branch git branch -r git branch -a 브랜치 생성 및 체크아웃 git clone --branch <브랜치> <저장소 url> git branch <새로운 브랜치> git checkout <브랜치> git branch <새로운 브랜치> <브랜치를 생성할 위치> git branch -f <기존 브랜치> [<브랜치를 생성할 위치>] 브랜치 합치기 및 삭제 git merge <브랜치> git merge --no-commit <브랜치> git cherry-pick <커밋명> git cherry-pick -n <커밋명> git merge --squash <브랜치> git branch -d <삭제할 브랜치> git branch -D <삭제할 브랜치>
4. 이력 조회 명령어
로그 조회 git log git log -p git log -<갯수> -p git log --since="1 hours" git log --before="2 days" git log -1 HEAD-5 git log -1 HEAD^^^^^ git log -1 HEAD~1^^^^ git log <시작 지점>...<끝 지점> git log --pretty=oneline git log --stat git log --name-status 차이점 보기 git diff git diff --cached git diff HEAD git diff <시작 지점> <끝 지점> git diff --stat <시작 지점> [<끝 지점>] 기타 git blame <파일> git blame -C -C <파일>
5. 원격 저장소 명령어
원격 저장소 복제 및 가져오기 git clone --depth 10 <저장소> git fetch git fetch <원격 저장소> git pull <원격 저장소> git pull 원격 저장소에 푸시 및 제거 git push <원격 저장소> <지역 브랜치>:<원격 브랜치> git push <원격 저장소> <지역 브랜치> git remote prune <원격 저장소> git remote rm <원격 저장소>
더 많은 명령어를 알고 싶다면 Git 공식 문서를 참고하세요.
이 포스팅을 통해 Git의 다양한 명령어들을 간단하게 살펴보았습니다. Git을 더 깊이 이해하고, 다양한 상황에서 효율적으로 사용할 수 있도록 연습해 보는 게 좋을 것 같습니다.