Git

[Git] Git 사용법

twoDeveloper 2021. 10. 26. 16:07

※ 참고 : https://rogerdudler.github.io/git-guide/index.ko.html

 

git - 간편 안내서 - 어렵지 않아요!

 

rogerdudler.github.io

 

1) 새로운 저장소 만들기

$ git init

· 해당 폴더에 .git 생성

 

2) 변경 파일 Index에 추가

$ git add [file_name]

$ git add .

$ git status # 현재 상태 확인

 

3) 변경 내용 확정

$ git commit -m "확정본에 대한 설명"

· 변경된 파일이 Head에 반영되었지만, 원격 저장소에는 아직 반영되지 않음

 

4) 내가 누구인지 config 설정

· 설정해주지 않았을때 다음과 같이 출력

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

4-1) git config 설정

$ git config --global user.email "you@example.com"

$ git config --global user.name "Your Name"

4-2) git config 삭제

$ git config --unset --global user.name

$ git config --unset --global user.email

4-3) git list 확인

$ git config --list

 

 

5-1) 기존에 있던 원격 저장소를 복제 한 것이 라면

$ git push origin master

5-2) 기존에 있던 원격 저장소를 복제 한 것이 아니라면

$ git remote add origin [원격 서버 주소]

5-2-1) ssh로 접근할 경우

$ git remote add origin [SSH 주소]

$ git remote -v

5-2-2) ssh-key 생성

$ ssh-keygen

5-2-3) id_rsa.pub key

$ cat ~/.ssh/id_rsa.pub

5-2-4) Git Page에서 'Settings' -> 목록에 'SSH and GPG keys' -> New SSH key -> id_rsa.pub key 복/붙 -> key 등록

 

5-2-5) 원격 저장소에 Push

$ git push origin master