자주 사용하는 Git command

froajnzd·2023년 9월 16일
0

git

목록 보기
2/5
post-thumbnail

깃 명령어집

설정/초기화

전역 사용자명/이메일 구성하기

$ 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”

참고로 user 설정이 되어 있지 않으면 Github에 있는 repository에 변경사항을 푸시 한다고 해도 commit count 집계도 안되고 해당 커밋의 작성자 프로필 아이콘도 ? 로 표시되기 때문에 웬만하면 name과 email 주소를 설정하길 추천한다.


전역 설정 정보 조회

$ git config - -global - -list


저장소별 설정 정보 조회

$ git config - -list

깃 프로젝트 클론

$ git clone

변경사항 저장

local storage에 변경사항 저장. '.' 을 쓰면 모든 변경사항

$ git add .		

로컬 레포지토리에 (add 한)변경사항 기록
$ git commit

git 저장소에서 데이터(objects and refs) 다운로드
$ git fetch

원격 저장소의 정보를 로컬 저장소로 끌어오기
$ git pull

둘 이상의 레포를 병합
$ git merge

커밋한 내용을 원격 저장소에 올림
$ git push

변경사항 조작

working tree의 untracked file들을 삭제

$ git clean

GIT LOG

깃 commit 로그 출력

$ git log

BRANCH

로컬에 있는 모든 브랜치 출력

$ git branch

현재 브랜치 변경
git checkout <branch-name>
git switch <branch-name>

GIT STASH

https://git-scm.com/book/ko/v2/Git-%EB%8F%84%EA%B5%AC-Stashing%EA%B3%BC-Cleaning

$ git stash						# Staging Area에 추가한다.

$ git stash list				# 저장한 Stash를 확인한다.
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log

$ git stash apply				# Stash를 적용한다. Stash는 여전히 스택에 남아 있다.

$ git stash apply --index		# Staged 상태까지 적용한다.

$ git stash pop					# 바로 stash를 적용하고, 스택에서 삭제해준다.

$ git stash drop stash@{0}		# 해당 stash를 삭제한다.
Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)

1. Current branch에서 개발 중에
Other branch에서 잠시 개발해야하는 상황이 생겼다
하지만 Current branch에서 commit을 하고 싶지는 않다..
(다른 브랜치로 넘어가기 위해서는 현재 브랜치에서 commit을 해야함)
그 때 stash를 통해 변경사항을 잠시 저장해 둘 수 있다

$ git stash
$ git checkout [other branch]
$ git checkout [Current branch]
$ git stash pop

2. Current branch에서 개발 중
개발중인 상황이 current branch에서 개발하면 안되는 것임을 알게 되었다
new branch로 지금까지의 변경사항을 이동하고 싶을 때
이것도 git stash를 통해 다른 브랜치로 이동시킬 수 있다

$ git stash
$ git checkout [new branch]
$ git stash pop
profile
Hi I'm 열쯔엉

0개의 댓글