자주 쓰이는 Git을 정리해 봅시다.
Git-SCM 다운로드

Git 기본

Github clone

git clone 주소

git pull/fetch

# github의 변화를 로컬에 반영
git fetch

git pull 원격명 브랜치명
git pull orign master

git 정보 등록

git init 
git config --global user.name "gildong.hong"
git config --global user.email "xxxxx@xxxxxx"

git 상태

git status
git status -s (단축해서 보여짐)

git commit

git add -A
git commit -m "first message"
git status

git branch 생성

git branch 새브랜치 이름
git branch      #생성 내용 확인
git checkout 이동할_브랜치이름 (ex) git checkout master

#생성과 동시에 이동
git checkout -b 새브랜치이름
git checkout -b 새브랜치이름 origin/my-branch

git branch 삭제

git branch -D 브랜치이름

git 원격 branch 삭제

git push -d 원격브랜치명
git push -d origin my-branch

git branch 상태 확인

git branch
* master

git branch -a	(로컬과 원격까지 보여줌)
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

git checkout

원격 저장소 origin에 브랜치명을 새브랜치로 생성함.

git checkout -b 새브랜치명 origin/브랜치명 

git 상태 원복하기

git reset 커밋아이디번호 --hard

sourcetree의 경우 > 오른쪽마우스 > 이 시점까지 초기화 > 옵션 Hard

git 상태 잠시이동

git revert 커밋아이디번호

sourcetree의 경우 > 오른쪽마우스 > 커밋 되돌리기

Git 스킬업

git 병합

A branch를 B Branch로 병합할 경우, B브랜치로 이동하여 merge 명령어를 실행함.

git checkout master
git merge 병합할 브랜치 ( 새브랜치를 -> master에 병합한다는 의미)

git 병합 충돌


<<<<< HEAD (현재 변경사항)
text 내가 작성한 부분
================	*wirter
text 상대방이 작성한 부분
>>>>>> dafqweradsfasdfsafa (수신 변경 사항)


최종 병합 충돌이 생긴 파일을 모두 수정후
git add
git commit -m "text"

git 부분 병합

git cheery-pick 커밋아이디번호

git rebase

병합 내용을 일렬로 만들어 주는 방법.

# 상태 보기
git log --graph --all --decorate

# 모든 병합이 모두 1개의 history로 병합됨
git rebase 브랜치명

sourcetree의 경우 > 오른쪽마우스 > 재배치

git remote 수정 삭제

git remote -v
origin http://192.168.0.100/저장소이름.git (fetch)
origin http://192.168.0.100/저장소이름.git (push)

git remote set-url origin http://192.168.0.200/저장소이름.git

git Tag

git tag 생성할Tag명

# 등록한 Tag리스트 
git tag

# 태그 전체를 리모트 저장소에 Push
git push origin --tags

#특정 태그 1개만 리모트 저장소에 Push
git push origin 생성한Tag명

git 예외 등록

몇 가지 작성 규칙이 있습니다.

  • ’#’로 시작하는 라인은 무시, 주석 개념.
  • / 는 하위 적용이 아님.
  • ! 로 시작하는 패턴은 무시히지 않음
git 폴더 최상위에
.gitignore

gitignore sample

*.class
!sample.class       #위에서 class모두 무시라고했는데, sample.class는 무시하지 않는다는 의미

/test.java

src/*.java
doc/**/*.txt

최근에는 이렇게 한번에 생성해주는 사이트도 있습니다.
gitignore.io

Github 활용

등록

github에서 Repository 생성시 하기 안내 명력어가 표시됨.

git remote  (원격 저장소 등록 내용 확인)
git remote add origin https://github.com/xxxxx.git
git push -u orign master	(origin 저장소에 master 브랜치명을 생성하여 등록함)

github 등록시 2개 이상의 git ssh 등록 방법


.ssh/config
# Default account
Host github.com-account1
  HostName github.com
  User git
  IdentityFile ~/.ssh/git-addrss1/id_rsa

# Secondary account
Host github.com-account2
  HostName github.com
  User git
  IdentityFile ~/.ssh/git-addrss2/id_rsa

태그: ,

카테고리:

업데이트: