[Github] git command 정리

hooray·2021년 4월 5일
0
post-thumbnail

기본 명령어


  • git init
    - 새로운 local repository 생성
  • git add
    - 변경된 파일을 storage에 추가
  • git commit
    - add한 파일을 local repository에 저장
  • git push
    - local repository를 remote repository에 업로드
  • git clone
    - remote repository에서 파일 다운로드

github에 파일 업로드 방법


1) repository 생성

  • Github 홈페이지에서 repository를 생성합니다.

2) init 초기화

  • git이 추적할 수 있도록 .git 폴더 생성.
  • local repository를 생성하는 것을 뜻함.
$ git init

3) status 상태확인

  • git이 버전 관리 대상 파일들의 상태를 파악합니다.
$ git status
  • 명렁어가 동작하지 않을때 에러확인
  • 작업한 파일 외에 다른 파일이 수정되진 않았는지 확인

4) add 추가

  • git add 파일 명령어는 특정 파일을 추가하는 명령어입니다.
$ git add .
  • 위 명령어는 변경된 모든 파일을 local repository에 추가하는 명령어

5) commit 작성

  • commit 메시지를 작성합니다.
$ git commit -m "메세지 내용"
  • -m 옵션은 간단하게 한줄로 메시지를 작성
  • 긴 메시지로 작성시 git commit 명령어만 실행하면 됨.

6) remote 등록

  • remote repository를 등록합니다.
$ git remote add origin {remote repository address}
  • origin은 remote repository의 별칭을 의미
  • 매번 remote repository의 주소를 입력하는 것이 귀찮으므로 별명을 사용함

7) push 업로드

  • 파일들을 remote repository에 업로드합니다.
git push origin master
  • master는 branch의 이름이며, remote repository를 생성하면 기본적으로 master 브랜치가 생성됨
  • 브랜치는 독립적인 작업 공간을 말하며, 브랜치를 통해 협업이 수월해짐 중요!
  • master가 아닌 다른 branch로 push하고 싶으면, 아래와 같이 master를 특정 브랜치명으로 바꿔서 명령어를 실행
git push origin {브랜치명}

upload 요약정리

git init
git add .
git commit -m "메세지 내용"
git remote add origin {remote repository address}
git push origin {branch name}

github에서 파일 다운로드 방법


1) cd 경로이동

  • 다운로드할 경로로 이동합니다.
$ cd {다운 받을 폴더 경로}

2) clone 다운로드

  • remote repository의 URL을 확인하여 복사합니다.
$ git clone {remote repository URL}
  • 특정 브랜치를 clone하고 싶다면,
$ git clone -b {브랜치명} {remote repository URL}

download 요약정리

$ cd {다운 받을 폴더 경로}
$ git clone -b {브랜치명} {remotre repository URL}
profile
Stay hungry. Stay foolish.

0개의 댓글