GIT

Github repository 생성시 생기는 명령어 설명

meno1011 2022. 8. 29. 14:17
728x90

github에서 repository를 생성하면 

…or create a new repository on the command line 이라면서 

아래와 같은 명령어를 보여준다.

git init 
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/<username>/<repository-name>.git
git push -u origin main

위 명령어를 해석하자면 

1) git init

github 와 연결될 저장 폴더와의 관계를 초기화 해준다.

2) git add README.md

github repository에 README.md라는 파일을 추가 해준다.
주로 git add . 라는 명령어를 입력하여 수정되거나 추가되는 파일을 모두 추가할 때가 많다.

3) git commit -m "first commit"

add로 수정하거나 추가된 파일을 올릴때 git commit을 통해 명세를 남기는데
-m 이라는 옵션으로 "first commit" 이라는 메세지를 추가하여 명세를 자세하게 남긴다.

4) git branch -M main

git branch 옵션 -M의 설명은 아래와 같으며 기본적인 브랜치는 main으로 생성되게 된다.
-M move/rename a branch, even if target exists

브런치에 대해 추가 설명을 하자면

Maser / Slave / blacklist / whitelist 라는 인종차별적이거나 노예제도를 떠올리게 하는 예명은 사용하지 않기로 했습니다.
해서 Nathaniel Friedman이 – Github CEO 새로 프로젝트를 생성할 때의 메인 브랜치명이 master에서 main으로 변경되었습니다. 기존에 있던 프로젝트는 그대로 사용되고 있습니다.
그 외의 리스트는 다음과 같이 변경었습니다.
* master → main/default/primary
* slave → secondary
* blacklist → deny/exclude list
* whitelist → allow list

5) git remote add origin https://github.com/<username>/<repository-name>.git

ex: username이 meno이고 생성한 repository이름이 test-repository 일경우 아래와 같이 생성된다.
ex: git remote add origin https://github.com/meno/test-repository.git

6) git push -u origin main

git push 옵션 -u의 설명은 아래와 같으며 
"-u, --set-upstream    set upstream for git pull/status "
origin이라는 원격 저장소(github repository)에 main 브런치에 코드를 저장하겠다라는 명령어 이다.