728x90
반응형
git 사용자 정보
- git config --global user.name “{name}”
- git config --global user.email {email}
- git config --list
- 정보 확인
- git config {key} 확인 가능
git의 일반적인 사용 순서
- git init
- git 저장소로 만든다
- git diff
- git add 전에 수정내용 확인
- git add ~
- 커밋 할 파일 추가
- git commit -m "메세지"
- 커밋 메시지 남겨 버전 만들기
- git commit -am "커밋 메시지 내용"
- git commit 명령을 실행할 때 -a 옵션을 추가하면 Git은 Tracked 상태의 파일을 자동으로 Staging Area 에 넣습니다. 그래서 git add 명령을 실행하는 수고를 덜 수 있을 것입니다.
- 커밋 수정 (git commit --amend)
- git commit -a → 첫 push 안될경우 모두 커밋하는 명령어
- git pull origin master
- 커밋해주고 풀 해주고
- git remote add origin 원격주소 (없을경우)
- 기존에 있던 원격 저장소를 복제한 것이 아니라면 주소 알려주기
- git push oringin master
- 푸쉬 하기
- git push -u origin master이유는 Clone한 사람이 여러 명 있을 때, 다른 사람이 Push한 후에 Push하려고 하면 Push할 수 없기 때문에 먼저 다른 사람이 작업한 것을 가져와서 머지한 후에 Push할 수 있습니다.
- -u는 원격저장소로부터 업데이트를 받은 후 push를 한다는 의미이므로 습관적으로 -u 사용을 권장합니다.
git merge request
- Fork
- Fork 버튼 눌러서 포크
- clone, remote
- PC 에 clone 하기
- branch
- add, commit, push
- 난 내 레포 포크한 곳에 push 날
- pull request
- 내 레포를 원본 레포로 pull request 날림
- write에 @아이디 붙이면 메일 전송 가능
- merge pull request
- 확인 후 합치기
- merge 후 branch 삭제 및 동기화
- # 코드 동기화 $ git pull real-blog(remote 별명) # 브랜치 삭제 $ git branch -d develop(브랜치 별명)
git remote 관련
- git remote -v
- git remote add upstream 깃주소
- git fetch upstream
- git checkout master
- git merge upstream/master
- git push origin master
- git remote update
git 취소
- git add 취소
- git reset HEAD 파일명(없으면 전체 취소)
- git commit 취소
- git log → 목록 확인
- git reset --soft HEAD^ → 취소하고 staged 상태로 워킹 디렉토리에 보존
- git reset --mixed HEAD^ → 취소하고 unstaged 상태로 워킹 디렉토리에 보존
- git reset HEAD^ → 위와 동일
- git reset HEAD~2 → 마지막 2개의 commit을 취소
- git reset --hard HEAD^ → 취소하고 unstaged 상태로 워디에서 삭제
- git push 취소
- git reset HEAD^ → 가장 최근 커밋 취소
- git checkout -- → 특정 파일을 이전 파일로 되돌리기
- 파일 수정 시 특정 파일만 커밋 시점으로 돌리고 싶을 경우 사용
- git checkout -- (경로)
git cache 삭제
- git rm -r --cached
- git repository 삭제하고 같은 레포 이름으로 올릴 때 트리에 남아있어 이전 커밋이 올라가는 경우가 생김 그때 캐시 삭제 후 재 push
git remote
- git remote rm <origin>
- git remote update
git branch
- branch 생성과 동시에 변경
- git checkout -b {브랜치 명}
- branch 삭제
- git branch -D {브랜치 명}
- branch 명 변경
- git branch -m {브랜치 명 변경 전} {브랜치 명 변경 후}
- branch 변경
- git checkout {브랜치 명}
- branch 확인
- git branch -v
- branch 생성 및 원격 브랜치 가져오기
- git checkout -t origin/{branch 명}
- git branch --set-upstream-to origin/{branch 명}
- 로컬에서 브랜치 생성한 경우
git description
- git branch 설명 추가
- git branch --edit-description {branch}
- git branch 설명 보기
- git config branch.{branch}.description
git stash / 임시저장
- git stash # 현재 변경 사항들을 스택에 저장
- git stash list # 스태쉬 목록을 확인
- git stash apply # 가장 최근의 스태쉬를 다시 불러옴
- git stash branch-name # 스태쉬 이름을 branch-name으로 지정하고 스택에 저장
- git stash apply branch-name # branch-name 이름을 가진 스태쉬를 불러온다
git branch rename
- git branch -m old_name new_name
- git push origin :old_name
- git push --set-upstream origin new_name
git tag
- git tag -a v1.0 -m “version v1.0”
- 태그 걸고 메시지 남기기
- git show v1.0
- 특정 태그 확인
- git push origin v1.0
- 특정 태그만 push
- git push origin --tags
- 모든 태그 push
git merge
- git checkout -b hotfix-1.2.1 master
- hotfix 로 빠르게 수정할때
- 수정 완료 후 push 및 develop 으로 checkout
- git merge --no-ff hotfix-1.2.1
- git tag
- master로 checkout 후 동일하게 merge 진행
git 파일 및 폴더 삭제
- 파일 삭제
- 로컬, git 저장소 모두 삭제
- git rm {파일명}
- git commit -m “delete file”
- git push
- 로컬은 삭제하지 않고 git 에서만 삭제
- git rm --cached {파일명}
- git commit -m “delete file”
- git push
- 로컬, git 저장소 모두 삭제
- 폴더 삭제
- 로컬, git 저장소 모두 삭제
- git rm -rf {폴더명}
- git commit -m “delete folder”
- git push
- 로컬은 삭제하지 않고 git 에서만 삭제
- git rm --cached -r bin/
- git commit -m “delete folder”
- git push
- 로컬, git 저장소 모두 삭제
728x90
반응형