본문 바로가기
DevOps/- Github

Git 커멘드 정리

by Yoojacha 2023. 8. 10.

git config

git config --list

git config --global user.name "Kim Yoo"
git config --global --replace-all user.name "Kim Yoo"
git config --global user.email "kimyoo04eco@naver.com"
git config --global init.defaultBranch main     <-- main 디폴트 브렌치로

 

git init : git 생성하기 / 현재 있는 디렉토리를 깃에 연걸.. initialize repository
gh - git 명령 확인
gh repo view : git cli 실행
gh auth login : 깃 로그인

 

git status : working tree status
git diff (차이점 보기) q로 esc

 

git clone

git clone git_path : 코드가져오기
git clone -b 브렌치명 --single-branch 원격레포지토리 주소  <-- 특정 브렌치 한개만 가져오기

 

git log

git log: show verion
git log --all
git log --all --oneline
git log--stat : 연루파일 보여주기
git log -p : 커밋별 추가된 사항들이 보임

 

git checkout

git checkout branch_name : 브랜치 선택하기
git checkout -t remote_path/branch_name : 원격 브랜치 선택하기
git checkout (커밋 아이디)
git checkout (master) :마스터와 마스터가 있는 커밋값에 checkout하는 것은 서로 다름

 

git checkout

git branch branch_name : 브랜치 생성하기
git branch -r : 원격 브랜치 목록보기
git branch -a : 로컬 브랜치 목록보기
git branch -m branch_name change_branch_name : 브랜치 이름 바꾸기
git branch -d branch_name : 브랜치 삭제하기
git branch -M main

 

git commit

git commit : creat verstion
-- git commit -m "message 1"
git commit -am "4" : add와 commit을 같이 한번에 함
git commit -m “commit_description” : 선택한 코드 설명 적기 ( git commit -m “내용”)
git commit --amend : 직전 커밋 메시지 수정 // :qa! 엔터 - 저장안하고 탈출 // :wq! 엔터 - 저장

 

git push

git push -u 원격저장소명 브랜치명
git push
git push remote_name — delete branch_name : 원격 브랜치 삭제하기 ( git push origin — delete gh-pages )
git push romote_name branch_name : add하고 commit한 코드 git server에 보내기 (git push origin master)
git push -u origin +master   <--- 초기 git pull 오류 생겼을때 pull 고려하지 않고 넣기

 

git fetch : git서버에서 최신 코드 받아오기

git pull : git서버에서 최신 코드 받아와 merge 하기

git merge 브랜치명 : ctrl x로 esc함 // 마스터가 가리키는 상태에서 merge하기

 

git reset

git reset — hard HEAD^ : commit한 이전 코드 취소하기
git reset — soft HEAD^ : 코드는 살리고 commit만 취소하기
git reset — merge : merge 취소하기
git reset — hard HEAD && git pull : git 코드 강제로 모두 받아오기
git reset --help : reset 하는 방법에 대해 나열해줌

 

git stash

git stash / git stash save “description” : 작업코드 임시저장하고 브랜치 바꾸기
git stash pop : 마지막으로 임시저장한 작업코드 가져오기

 

git branch

git branch — set-upstream-to=remote_path/branch_name : git pull no tracking info 에러해결

git add

git add . : 현재 가리키는 디렉토리 밑의 변경된 모든 파일을 add 시킴
git add 파일명 : add to staging area
git add 디렉토리명
git add file_path : 수정한 코드 선택하기 ( git add * )

 

git remote

git remote 저장소명 알아내기
git remote add origin https://github.com/깃허브아이디/레포지토리명
git remote add
git remote add origin (저장소명)

 

gitignore 적용 안될 때

git rm -r --cached .


https://kyportfolio.tistory.com/273

 

git stash를 애용하자

git에 대한 오해를 가지고 첫 회사에 들어가다 보니, 저의 시야가 바뀌는 계기가 된 stash에 대해서 정리했습니다. 프로젝트를 망치기 무섭다는 마음에 git cli를 소극적으로 썼다는 것을 깨달았습

kyportfolio.tistory.com

 

댓글