카테고리 없음

깃허브 기초-1

jihuSunbae 2024. 7. 6. 10:46
카카오 부캠 팀 미션의 일환으로 깃허브 설정을 했는데, 

경험해보지 않아서, 관련 공부를 하기 시작했다. 

 

 

강의는 드림 코딩 '깃 제대로 배워보자'를 들었습니다. 

https://www.youtube.com/watch?v=Z9dvM7qgN9s

 

 

 

    • command: 명령어 모두 사용 가능
    • iterm2 를 사용하면 보기 좋게 command 사용 가능(근데 맥에서는 똑같았다.?)
    • sourcetree / gitcraken(UI 좋음)
  • 깃 명령어 홈페이지: Git - Reference

 

깃의 주요 컨셉

구조

이미지 출처:  https://www.youtube.com/watch?v=Z9dvM7qgN9s

 

  • local
    • working directory: 실제 작업소
      • untracked file : git로 한 번도 추가 된 적 없는 파일
        • modified / unmodified 로 구성됨
      • tracked file: git로 한 번도 추가되어 계속 트랙하고 있는 파일
    • staging area : 어느 정도 준비가 된 파일을 저장하는 곳 (git add)
    • local repo
  • Remote repo
    • staging area → localrepo ; (git commit)
깃 주요 명령어
git add: move files from working directory to staging area
git commit -m “commit msg”: move files from staging area to local git directory
git push: copy files from local git directory to remote git directory
git pull: copy files from remote git directory to local git directory

 

깃허브 설치 및 초기화

  • 설치: homebrew install git
  • 계정 설정: 이름 & 이메일
  • 원격 저장소 생성 : github 홈페이지 들어가서 repository 생성
  • git init: 로컬 저장소 초기화 - 업로드 하고 싶은 디렉토리 안에 들어가서 명령어 수행
    • 아래와 같이 숨겨진 .git 디렉토리 생성됨 (ls -al 명령어 사용)
    • ./git 생성과 함께 main branch가 생성
  • 원격저장소-로컬 저장소 연결: git remote add origin https://github.com/[사용자 이름]/[저장소 이름]

 

로컬 파일 원격 저장소에 업로드

git add : staging area로 선택한 파일 업로드 (git add . 모든 파일 선택 git add *.format 특정 포맷 선택)
git commit -m "commit msg”: 선택한 파일들을 묶어 하나의 버젼으로 만들어줌 
git push -u origin main: 원격 저장소 메인 줄기에 컴퓨터 파일 깃헙 원격저장소에 업로드

 

깃 주요 명령어

기본 형태: git {명령어} -option

  • git --version : 깃 버젼 체크
  • git config --list
  • git status
    • git status -s : 간단 버젼
  • git config —gloabl alias.{단축키} {원래 단축할 명령어}: git 명령어 단축키
  • git add <파일>
    • git add . git add *.format
  • git rm —-cached <파일> : git add 취소
    • staging area→ working directory = untracked로 만들어짐
  • git diff: 파일이 어떻게 변경 되었는지를 나타내준다.
    • 아래와 같은 결과창이 뜬다. 

기타 설정

  • git config --global core.editor "code” → config 파일 editor에서 열수 있도록 설정
  • .gitignore 파일
    • 트랙하지 않고 싶은 파일 유형들을 기록해둔 파일 (e.g. 로그)
    • 먼저 파일을 만들어야 함 : touch .gitignore
    • 내용 작성

 

 기타

  • 리눅스 파일 선택
    • *.format 특정 포맷 가진 이들 선택
    • direct/ 특정 디렉토리
    • direct/.format 특정 디렉토리 내 특정 포맷 선택
  • ls -al : 숨겨진 파일까지 조회
  • open: 숨겨진 파일 열기

 

 

기타 설정

  • git config --global core.editor "code” → config 파일 editor에서 열수 있도록 설정
  • .gitignore 파일
    • 트랙하지 않고 싶은 파일 유형들을 기록해둔 파일 (e.g. 로그)
    • 먼저 파일을 만들어야 함 : touch .gitignore
    • 내용 작성