본문 바로가기

Git

git과 github 사용법 간단정리

git 설치


git이 설치되어 있지 않다면 설치한다.

https://git-scm.com/downloads

 

Git - Downloads

Downloads Mac OS X Windows Linux/Unix Older releases are available and the Git source repository is on GitHub. GUI Clients Git comes with built-in GUI tools (git-gui, gitk), but there are several third-party tools for users looking for a platform-specific

git-scm.com

 

설치하고 terminal에서 git버전 확인

 

 

 

git 저장소 만들기


git저장소 만들기를 원하는 프로젝트의 터미널에서 명령어 입력

git init

 

 

현재 git의 상태를 보자 명령어 입력

git status

 

 

루트디렉터리에 .gitignore라는 이름의 파일을 생성한뒤, node_modules와 같은 크기가 크지만 관리에 필요없는 디렉터리를 적어준다. (생략가능)

 

 

아래 명령어로 프로젝트 파일들을 staging area로 옮기자

git add .

상태를 확인하면 node_modules디렉터리는 없음

 

대기구역에서 git저장소로 옮기자. -m뒤엔 아무거나 적어도됨

git commit -m "message"

staging area에 있던 파일들이 저장소에 모두 올라갔다.

 

 

 

git add는 작업디렉터리에서 변화가 일어나고 저장소에 업데이트 하기 위해서 staging area로 옮긴다는 것이다.

git commit을 하면 변화된것을 git저장소에 저장한다는 것이다.

그 다음의 remote공간은 local공간이 아닌 github에 프로젝트를 저장하는것.

이걸 위해서 로컬의 git, 그리고 github를 연결해보자

 

 

 

SSH를 이용해 git과 github 연결


우선 github에 연동을 위한 저장소를 생성한다.

 

 

연동을 위해 SSH키가 필요하기 때문에 생성해준다. 아래 사이트를 보고 그대로 따라하면 된다.

https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

 

Generating a new SSH key and adding it to the ssh-agent - GitHub Help

Generating a new SSH key and adding it to the ssh-agent After you've checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent. Mac Windows Linux All If you don't already have an SSH key, you must

help.github.com

👇

git bush를 열고 아래를 복사한다음 엔터엔터엔터

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
$ eval $(ssh-agent -s)
$ ssh-add ~/.ssh/id_rsa

 

 

생성한 후에는 이 키를 github에 붙여야한다. 아래사이트를 보고 따라하면 된다.

https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account

 

Adding a new SSH key to your GitHub account - GitHub Help

Adding a new SSH key to your GitHub account To configure your GitHub account to use your new (or existing) SSH key, you'll also need to add it to your GitHub account. Mac Windows Linux All Before adding a new SSH key to your GitHub account, you should have

help.github.com

👇

아래 명령어는 SSH 키값을 복사하는 것이다.

$ clip < ~/.ssh/id_rsa.pub

github의 setting메뉴 클릭

아래 메뉴 클릭

 

이곳에 복사된 키값을 넣으면 된다.

 

 

그리고 프로젝트 터미널로 다시 돌아가서 다음 명령어를 입력한다.

(github메인에 있는 명령어)

 

 

git과 잘 연결된것을 볼 수 있다.

 

 

'Git' 카테고리의 다른 글

github.io에 react app 설치하는 법  (0) 2020.03.12