Git과 버전관리
•
버전
◦
유의미한 변화가 결과로 나온 것 또는 이를 구분하는 지점
◦
패치: 시급한 오류 해결이나 비교적 규모가 작은 버전
•
버전 관리 시스템
◦
언제, 누가, 어떤 부분을 어떻게 변경했는지 확인 가능
◦
수정된 내용을 쉽게 공유
◦
특정 시점으로 돌아갈 수 있음
◦
Git은 저장할 공간만 있다면 어디서나 사용 가능
•
Macbook에서 branch 이름 보이게 하는 방법
•
git 설정 및 내용 정리
◦
최초 설정
git config --global user.name "본인이름"
git config --global user.email "본인 이메일 주소"
# 확인
git config --list
Plain Text
복사
◦
저장소 만들기
git init
Plain Text
복사
◦
추가할 파일 더하기
git add .
Plain Text
복사
◦
상태 확인
git status
Plain Text
복사
◦
커밋
git commit -m "메세지"
Plain Text
복사
◦
repository와 나의 로컬 프로젝트 연결
git remote add origin https://github.com/minsung/test.git
Plain Text
복사
◦
잘 연결되었는지 확인
git remote -v
Plain Text
복사
◦
깃허브에 업로드 (push)
git push origin main
Plain Text
복사
•
github 공유주소 링크
Github 블로그 만들기 - 터미널에서 실행
•
github 블로그 생성
~/Desktop/test $ git clone https://github.com/codesche/codesche.github.io.git
Cloning into 'codesche.github.io'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
~/Desktop/test $ ls
blog company testproject
codesche.github.io home
~/Desktop/test $ cd codesche.github.io
~/Desktop/test/codesche.github.io (main)$ ls
README.md
~/Desktop/test/codesche.github.io (main)$ rm -rf *
zsh: sure you want to delete the only file in /Users/haminsung/Desktop/test/codesche.github.io [yn]? y
~/Desktop/test/codesche.github.io (main)$ ls
~/Desktop/test/codesche.github.io (main)$ ls -al
total 0
drwxr-xr-x 3 haminsung staff 96 7 1 15:49 .
drwxr-xr-x 8 haminsung staff 256 7 1 15:49 ..
drwxr-xr-x 12 haminsung staff 384 7 1 15:49 .git
~/Desktop/test/codesche.github.io (main)$ ls
~/Desktop/test/codesche.github.io (main)$ git add .
~/Desktop/test/codesche.github.io (main)$ git commit -m "first commit"
[main 1d9d422] first commit
3 files changed, 95 insertions(+), 2 deletions(-)
delete mode 100644 README.md
create mode 100644 index.html
create mode 100644 style.css
~/Desktop/test/codesche.github.io (main)$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 10 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 1.10 KiB | 1.10 MiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/codesche/codesche.github.io.git
c7c3e08..1d9d422 main -> main
~/Desktop/test/codesche.github.io (main)$
Shell
복사
•
github.io 접속
npm install
npm start
# react 브랜치 생성
git switch -c react
# 브랜치 리스트 확인
git branch -l
# 파일 삭제
rm -rf *
# 에러나서 sudo로 변경 후 실행
npm i -g yarn
sudo npm i -g yarn
# React 폴더 생성
yarn create react-app .
yarn add gh-pages -D
Shell
복사
•
package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"deploy": "gh-pages -d build" // 추가
},
JSON
복사
•
홈페이지 추가
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"deploy": "gh-pages -d build"
},
"homepage": "https://codesche.github.io/", // 추가, 띄어쓰기 하지 말것
JSON
복사
•
react 브랜치에 commit, push
git add .
git commit -m 'react setting'
git push -u origin react
yarn build
yarn deploy
Shell
복사
•
Github Pages > Deploy from a branch 로 설정 후 저장
•
정리
- 리액트 소스 수정
- git add .
- git commit -m ‘메시지’
- git push
- yarn build
- yarn deploy
Shell
복사
•
yarn local 에서 시작하는 방법
yarn start
Shell
복사
기타
git push origin master을 했는데 아래와 같은 에러가 뜨는 경우가 있다.
에러의 이유는 현재 브런치가 main인데 master branch에 푸시를 했기 때문이다.(로컬 환경에서 처음 git을 설정할때 main으로 생성되는 경우와 master로 생성되는 경우가 있다)
해결 방법
“git push origin main”으로 명령어를 재입력하거나, 혹은 master 브랜치에 올려야 할 경우 다음과 같은 순서로 명령어를 입력해 준다.
“앞부분 생략~”
Plain Text
복사
”git branch -M master"
Plain Text
복사
“git remote add origin https://github.com/heewonkimm/test.git”
Plain Text
복사
“git push -u origin main”
Plain Text
복사