티스토리 뷰

카테고리 없음

git & github 정리

마이스토리 2021. 10. 4. 20:23

git install

  • windows

    • git-scm.com 에서 설치파일 다운로드
    • git-bash 실행
  • unix / linux

    • $ sudo apt-get install git
    • $ sudo yum install git
  • codeonweb.com : 다양한 온라인 개발 실습환경 제공

git 명령어

$ git init #저장소 생성 및 초기화
$ git status #상태조회
$ git add #버전관리에 추가(신규파일 뿐만 아니라 버전관리 소스를 수정한 후에도 add한 변경사항만 commit된다.)
$ git config --global user.name jnj45 #사용자명 설정
$ git config --global user.email jnj45@hanmail.net #사용자 이메일 설정
$ git commit
$ git commit -a #변경된 소스를 모두 자동으로 add한 후 commit(단, 한번 이상 adde된 파일만)
$ git commit -am "메세지" #인라인 커밋메세지 추가
$ git commit --amend #마지막 commit 메세지 수정

$ git log
$ git log -p # 변경내용 소스코드 같이 확인
$ git diff 
$ git diff commitid1..commitid2
#stage area : commit 대상을 관리하는 영역

$ git branch [branch name] # branch 생성
$ git checkout [branch name] # 해당 branch로 switch
$ git checkout -b [branch name] #branch를 만들면서 checkout까지 한다.

$ git log --branches --decorate --graph --oneline
$ git log [branch name1]..[branch name2] #branch간의 차이. ex) git branch exp..master
$ git log -p [branch name1]..[branch name2] #파일목록까지 표시
$ git log --reverse # 역순으로 로그조회
$ git diff master..exp #파일의 내용까지.

$ git merge [branch name] #해당 branch의 내용을 병합
$ git branch -d [branch name] #해당 branch를 삭제.

#fast forward : branch이후 ancestor의 commit이 없는 경우
#recursive merge : branch이후 ancestro의 commit이 생기 경우. 내부적으로 자동 commit object 생성됨.

$ git stash <save> # 현재 작업 중인 내용을 임시로 숨긴다? (버전관리되고 있는 파일들만 대상.)
$ git stash apply #save했던내용을 복원
$ git stash drop #최신 stach를 삭제
$ git stash pop # apply와 drop을 한번에 처리.
$ git stash list

$ git reset --hard HEAD

#merge 시 충돌이 나면 수동으로 소스를 수정한 후 git add, git commit 한다.

$ git reset --hard [commit id] # HEAD의 최신 commit을 [commit id]를 가르키게 한다.
$ git reset --hard ORIG_HEAD # 앞서 reset한 내용을 취소하고 복구한다.
$ git reflog # 작업로그 조회

$ git revert [commit id]

$ git reset --soft [commit id] # repository 만 reset
$ git reset --mixed [commit id] # repository와 index(staging area) 를 reset
$ git reset --hard [commit id] # working directory까지 reset, commit id를 생략하면 가장 최신 commit으로 적용.

$ git config --global merge.tool kdiff3 # 병합 툴 설정.
$ git mergetool #병합툴 실행.

$ git init --bare [directory명] # 저장소 역할만 하는 working directory가 없는 원격저장소 만들기.

$ git clone [원격저장소url] [디렉토리명] #원격저장소의 repository clone. 디렉토리명이 . 이면 현재 디렉토리로 생성.

$ git remote add origin [원격저장소url] #로컬저장소를 origin이라는 별명의 원격저장소와 연결. 여러개의 원격저장소와 연결할 수 있음.
$ git remote -v #원격저장소 목록
$ git remote remove [원격저장소 이름] #원격저장소 연결 해제

$ git push -u origin master #로컬저장소의 브랜치를 원격저장소에 push (제일 처음 push)
$ git push #처음 push한 연결로 push

$ git pull #원격저장소의 내용을 당겨온다.

#ssh연결하기
$ ssh-keygen
$ cd ~/.ssh #id_rsa, id_rsa.pub 파일 2개가 생김.
# id_rsa.pub 파일내용을 github의 ssh key로 등록.
$ git remote add origin git@github.com:jnj45/gitfth.git
$ git clone git@github.com:jnj45/gitfth.git
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31