Thoughts, stories and ideas.

Git

기본설정

$ rm -rf ./.git  #초기설정을 위한 삭제 (필요시)
$ git init
$ git add .
$ git commit -m "Comments"
$ git remote add origin <url>
$ git push -u origin master
$ git remote -v

$ git push --force --set-upstream origin master


$ gitignore
git rm -r --cached . #Repository cache 모두 삭제
git rm -r --cached [File name] #File name에 해당하는 파일을 원격 저장소에서 삭제
git add . # .gitignore 넣은 파일 목록 제외하고 모든 파일 다시 track
git commit -m "set gitignore"
git push origin master




## 오류사항



[Git오류] [rejected] master -> master (fetch first)
$ git push origin +master #강제푸시 > 기존 데이터 날라갈 수 있음
# Git pull 로 데이터 내려받고 진행할 것


# reset 의 경우 히스토리를 삭제함
git fetch --all 
git reset --hard origin/master


# Git push 안되는 경우 (fatal: refusing to merge unrelated histories)
git pull origin 브런치명 --allow-unrelated-histories
--allow-unrelated-histories
서로 관련 기록이 없는 이질적인 두 프로젝트를 병합할 때 허용

SourceTree

설치 시, BitBucket 로그인 연결 하지 말 것

도구 > 옵션 > 인증 탭에서 계정삭제

설치 https://uxgjs.tistory.com/181

완벽하게 삭제하는법

  1. 제어판 > 프로그램 추가 제거 > 제거
  2. 하기 폴더에서 파일들 삭제
    %AppData%\Local\Atlassian
    %AppData%\Local\SourceTree
    %AppData%\Roaming\Atlassian

ETC

  • 2020.10 부로 메인 기본 브랜치가 master > main으로 변경됨
    (master 라는 명칭에 대한 논란으로 변경)

  • 브랜치 관리
    git branch 목록
    git branch subdir01
    git checkout subdir01 #지점 이동 >> git pull 로 작업
    git checkout -b subdir01 #지점 만들기및이동

  • 브랜치 병합
    git check master
    git merge subdir01 (sub1 브랜치 결과 병합)
    git push origin master

  • 브랜치 삭제
    git branch -d subdir01

  • git log #히스토리 탐색

  • git grep 파일 내용에서 검색


AWS CodeCommit
실습 참고블로그 https://cloud-oky.tistory.com/41
소스트리+CodeCommit https://midasitwebop.tistory.com/33

충돌 났을때

git fetch --all
git reset --hard origin/master
git pull origin master
  1. 수정한 파일이 conflict되면 fetch로 파일들을 remote 저장소에서 이전 fetch들을 받는다.
  2. local에서 다시 reset hard를 사용하여 컨플릭트 나기전인 수정하기 전으로 되돌림
  3. 이후 pull 하면 remote에서 loacal로 정상적으로 다운