22.03.29 TIL

조은지·2022년 4월 3일
0
post-thumbnail

# Clone으로 First repo만들기

- README.md파일 수정하여 github에 업로드하기

  1. github에서 저장소(Repository)를 만든다.
  2. 주소를 복사하여 dev폴더에서 $ git clone [주소]를 입력한다.
    최초 로그인할 때 github에서 토큰을 발급 받아 복사한 뒤, shell에서 $ git push origin main을 입력하여 뜬 로그인 창에 복사한 토큰을 넣어주면 됨!
  3. 해당 폴더에서 $ git status를 입력한다.
$ git status
On branch main
Your branch is up to date with 'origin/main' 
Changes not staged for commit: 
# commit하기 위해 staging되지 않은(앞접시에 올라오지 않은) 변경 사항이 있다는 뜻
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md
no changes added to commit (use "git add" and/or "git commit -a") 
  1. 올리고 싶은 파일을 $ git add [파일명.확장자]로 staging해준 뒤 상태를 확인한다.
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
# 앞접시에 README.md를 덜어낸 상태
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md  
# 이제 commit해서 스냅샷 찍어주면 됨
  1. $ git commit하여 커밋 메시지를 작성한 후 상태를 확인한다.
$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean
# 커밋 완료! 이제 push 해서 올림
  1. $ git push origin main: main(local)에서 origin(remote)로 push한다는 뜻

# 새로운 파일을 만들었을 경우

  1. $ touch [파일명.확장자]로 새로운 파일을 만든다.
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Untracked files: 
# Untracked files = 처음 보는 파일(새 파일)
  (use "git add <file>..." to include in what will be committed)
        main.py
nothing added to commit but untracked files present (use "git add" to track)
# 현재 빈 파일
  1. main.py와 README.py를 모두 수정 후 $ git status했을 때
$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md
        modified:   main.py
no changes added to commit (use "git add" and/or "git commit -a")
# 두 파일의 역할이 다르기 때문에, 동시에 커밋하지 않고 작업 단위를 구분해야함!
  1. 각각 add와 commit을 해준 뒤 push로 업로드한다.

# git init으로 Second repo만들기

  1. $ mkdir second-repo로 디렉토리를 만든다.
$ git status
  fatal: not a git repository (or any of the parent directories): .git
# 해당 폴더는 repo가 아니라는 뜻
# 이유 : 아직 해당 폴더를 저장소라고 명명한 적 없음. 그래서 git으로 아무것도 할 수 없는 것!)
  1. $ git init을 입력하여 해당 폴더를 git으로 선언한다.
    빠져나오는 법 : .git이라는 파일 찾아서 지우면 된다!
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
# 선언 하기 전과 달리 git에 반응하는 것 확인 가능.
  1. $ git remote를 해보면 처음에는 아무것도 안 뜨는데, 이것은 '보내는 사람'은 적었지만 '받는 사람'은 적지 않은 것과 같다.
    따라서 github에서 저장소(repo)를 만든 후 주소를 복사하여 $ git remote add [저장소 별명] [주소]로 설정해줘야한다.
    # 보통 [저장소 별명]으로 origin을 많이 쓴다!
    # 여기까지 하면 클론했을 때와 상황이 같은 것! 이제 add commit push만 남음.
  2. remote를 github 저장소로 연결시켜준 뒤, README.md를 만들어준다.
  3. 해당 폴더의 기본 branch명은 master이기 때문에 github처럼 main으로 바꿔준 뒤, add commit한다.
$ git status
On branch master
# github에서는 기본 branch명이 'main'이라서 둘이 맞춰주기 위해 'master'->'main'으로 바꿔줘야함.
No commits yet
Untracked files: 
# git이 처음보는 파일이 생성됐다는 뜻!
  (use "git add <file>..." to include in what will be committed)
        README.md
nothing added to commit but untracked files present (use "git add" to track)
$ git branch -M main
# branch이름이 main으로 바뀐 것을 확인할 수 있음!
$ git status
On branch main
nothing to commit, working tree clean
  1. 완료한 commit을 push해준다.

    # 첫 push할 때 주의사항!!
  $ git push -u origin main

: clone은 remote에 있는걸 그대로 복제 해와서 건드릴 필요 없지만, init 방식은 각각 존재하며 이름만 같은 것이기 때문에 상관관계를 만들어준 적 없다.
따라서 -u(upstream set)를 통해 연결시켜주어야한다.
-받는 사람이 remote, 보내는 사람이 local!
-여기서는 origin이 받는 사람/ main은 보내는 사람

  1. 이후 $ git status했을 때 마지막 줄인 "branch ‘main’ set up to track ‘origin/main’ => branch main"이 origin를 추적하도록 설정됐다는 뜻이다.

# Commit Convention

  • 첫 글자는 대문자로! (가독성을 위해)

  • commit은 동작 가능한 최소단위로 자주 만들 것.

  • 해당 작업단위에 수행된 모든 파일 변화가 해당 commit에 포함되어야 함.

  • 모두가 이해할 수 있는 log를 작성할 것.

  • Open Source Contribution시 영어가 강제되지만, 그렇지 않을 경우 팀 내 사용 언어를 따라 쓸 것.

  • 제목은 축약하여 쓰되(50자 이내), 내용은 문장형으로 작성하여 추가설명 할 것.

  • 제목과 내용은 한 줄 띄워 분리할 것.

  • 내용은 이 commit의 구성과 의도를 충실히 작성할 것.

  • prefix를 사용하여 한 눈에 커밋의 용도를 알기 쉽게 한다

    # prefix

    ex) feat: features (기능구현)
    docs: documentations (문서작업)
    conf: configurations (환경설정)
    test: test
    fix: bug-fix (기능 잘못된 걸 바로잡기/malfunction에 대해 수정)
    refactor: refactoring(잘 돌아가는 코드를 enhancement시키는 것)
    ci: Continuous Integration
    build: Build
    perf: Performance

  • prefix ex)

feat: Create server.py to start flask project
docs: Create README.md
conf: poetry init
test: User model CRUD test complete

0개의 댓글