교육 (Today I Learned)/Hanaro

[Hanaro] 5일차 / Git 시작하기, Git Branch

Bay Im 2024. 1. 19. 17:49

컴퓨터 아키텍쳐

  • DBMS(Database Management System)
    • RDBMS(MySQL, Postgresql, Oracle, MS-SQL)
    • DocumentDB(MongoDB, DynamoDB, MySQL XDev/API)
  • Network
    • Router(Routing Table), DNS(Domain Name System), Switch, Hub TCP(Transmission Controll Protocol), UDP(User Datagram Protocol)
  • Cloud(OnDemand/OnPremise)
    • InfraaaS, PlatformaaS(Firebase, DevOps, Kubernetes, S3, BigQuery), SoftwareaaS(GoogleApps)
  • Library/Framework, Clean Architectire, Messaging Queue

 

Git 시작하기

  • git structure
    • working directory → stage (git add) → git local repository (git commit) → git remote(server) Repository (git push)
    • 파일수정→ modified(working dir)→ add→ modified(stage)→ commit→ unmodified(repo)
  • HEAD
    • 마지막으로 commit 한 것, 그 다음은 HEAD-1
  • tracked - untracked
    • stage에 들어가 있거나 들어가 있지 않은 상태
  • 명령어 별칭 부여
    • alias 별칭이름=’명령어’
    • ex) alias ll='ls -algs’
  • 로컬 저장소 만들기
    • git init
      • .git 디렉터리 생성
    • git clone <git-remote-url> [dirname]
      • remote repo와 clone 하기
    • git remote rm origin
      • 서버와 연결된 repo 끊기
  • git bash에서 파일 편집하기
    • vi 파일명
      • vi 편집기로 코드를 열고 수정 가능
      • i 누르면 커서 앞부터 입력
      • a 누르면 커서 다음부터 입력
      • :q 누르면 저장하지 않고 종료
      • :wq나 ZZ 누르면 저장하고 종료
    • touch 파일명
      • 파일명 이름으로 파일 생성
    • cat 파일명
      • 해당 파일명의 코드 내용 출력
    • echo ‘내용’ > 파일명
      • 해당 내용의 파일명 생성
  • git에 올릴 때 제외할 파일이 있을때
    • .gitignore 파일을 만들고 그 안에 해당 파일을 작성한다.
    • ex) vi .gitignore → 파일에 편집기로 제외파일.txt 작성
  • git 파일 올리기
    • git add .
      • 전체 파일 working dir에서 stage로 올리기
    • git ls-files
      • tracked 된(add) 파일 보이게 하기
    • git status
      • 파일 상태 확인
    • git rm —cached <file>
      • stage로 올린거 취소하기 (add 취소)
    • git commit -m “커밋 메시지”
      • commit 하기
      • 이후 git status 하면 commit 할게 없다고 나온다 (working tree clean)
    • git log
      • commit한 히스토리 출력 (커밋 메시지)
    • git pull origin main(master)
      • push 하기 전에 먼저 pull 해서 최신 버전으로 유지
      • history가 깨져서 pull이 되지 않는다면 git pull origin master --allow-unrelated-histories 로 pull 하기
    • git push origin main(master), git push -u origin master
      • git repository로 push
  • 브랜치 이름 변경
    • git branch -M 브랜치이름
      • ex) git branch -M master
  • fetch와 push
    • fetch
      • remote repository에서 local repository로 소스를 가져오는 명령어
      • pull = fetch + merge 이므로 fetch와 pull의 차이점은 소스를 merge 하느냐 안 하느냐의 차이다.
    • push
      • commit 된 내용을 remote repository로 내보내는 명령어
  • git add 되돌리기
    • git restore —staged 파일명 → git restore 파일명
      • 수정 전 상태(HEAD)로 돌아온다.
      • 원본 - 수정 - add(modified) - staged - restore —staged(modified) - restore - 원본
    • git restore 파일명
      • add는 안 한 상태로 파일만 수정 전 상태로 돌리고 싶을 때
  • remote repo에 있는 파일 삭제
    • git rm —chached 파일명
      • remote repo에서 파일 삭제 (local repo는 삭제 안됨)
    • git rm 파일명
      • local, remote repo 모두에서 파일 삭제

 

Git Branch

  • branch란
    • 가상 폴더 같은 것이며 독립적인 작업 공간이다.
    • 기본은 main or master
  • branch 생성
    • git branch <branch_name>
      • branch 만들기
    • git branch
      • branch 전체 보기
    • git checkout <branch_name>, git switch <branch_name>
      • 해당 branch로 전환
      • 이전 branch로 가기는 git checkout -
    • git checkout -b <branch_name>
      • branch 생성 + 이동
    • git push origin <branch_name>
      • 해당 branch로 push
    • git branch -d <branch_name>
      • 브랜치 삭제
  • branch with remote
    • git remote -v
      • 원격 저장소 링크 출력
      • 정보까지 출력은 git remote show origin
728x90