Programming/Linux

git 자주 사용하는 명령어 정리

DevMonster 2022. 5. 24. 17:13

[git 초기 설정]

git config --global user.name "<이름>"
git config --global user.email "<이메일>"

git config --global credential.helper store  // git push 할 때 사용되는 계정정보 저장

 

[SSH 에서 Github 접속가능하도록 공개키 등록]

ssh-keygen -t rsa -C "<이메일>"

user@computer:~/$ ssh-keygen -C

 

[origin 설정하기]

git remote add origin <URL.git>

git remote set-url origin <URL.git>  // 위 수행이 에러나면

 

[브랜치 생성]

git checkout <부모 브랜치>

git checkout -b <브랜치명>

 

[stage, unstage list 확인하기]

git status

 

[commit을 위한 stage에 올리기]

git add <filename>

git add .    // 현재 위치의 수정한 모든 파일 추가 (하위 폴더 포함)

 

[코드 수정 전으로 되돌리기]

git checkout -- <filename>            // 파일 1개

git checkout -- .                                 // 전체

 

[unstage]

git reset

git reset <filename>

 

[Stage 내용 commit 하기]

git commit -m "<메모>"git commit --gamend -m "<메모>"        // 직전 commit description 수정

 

[원격저장소 가져오기]

git clone <주소.git> // 현재 위치에 디렉토리 생성됨

git pull --rebase origin <브랜치명(e.g. main)> // fetch + rebase 되는 것 원격 main과 sync 맞출 때 주로 사용

git fetch origin <브랜치명> // 원격 브랜치의 수정사항 가져오기

git rebase origin <브랜치명>

 

[다른 브랜치에서 commit된 항목 가져오기]

git cherry-pick <commit 번호> // commit 번호는 git log 치면 나옴

 

[원격저장소에 commit된 항목들 넣기]

git push origin <branch이름(e.g. devmonster/bugfix)>

 

[코드 임시저장]

git stash // 저장

git stash apply <stash id(e.g. stash@{0})> // 불러오기

git stash drop // 가장 최근 저장한 stash 삭제

git stash drop  stash@{n} // stash id에 해당하는 것 삭제

git stash clear // stash 기록 모두 삭제

 

[파일 chmod 형식 diff 무시]

git config core.filemode false

728x90
반응형