목차
1) shell, vim commands
2) git basic - clone, add, commit, push
3) github pages
4) branch
5) git flow, github flow, gitlab flow
6) Co-work with git, github
1) shell, vim commands
$ pwd : 현재 디렉토리 확인
$ ls : 현재 폴더의 파일 리스트
$ ls -a : 숨김 파일 보기
$ ls -l : 파일 상세 리스트 보기
$ cd Documents/ : 폴더 위치 이동
$ mkdir dev : 폴더 만들기
$ touch hello.py : 빈 파일 만들기
$ mv README.md dest : 파일 이동 시키기
$ mv ../*.py ./ : 와일드 카드로 파일 이동 시기키
$ cp main.py ./main_copy.py : 파일 복사하기
$ mv LICENSE license.txt : 파일 이름 바꾸기
$ rm license.txt : 파일 지우기
$ rm -rf dest : 폴더 지우기
$ vi hello.md : 파일 편집
$ cat hello.md : 파일 내용 보기
$ git config --list : git 환경 설정 내용 보기
$ git config --global user.name "ktbaek72"
$ git config --global user.email "ktbaek72@gmail.com"
$ git config --global core.editor "vim"
$ git config --global core.pager "cat"
$ git config --global alias.lg "log --graph --pretty=tformat:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --decorate=full"
vim commands
h j k l - left, down, up, right
i - insert mode
v - visual mode
ESC - back to normal mode
d - delete
dd - delete a line
y - yank
yy - yank a line
p - paste
u - undo
a - append
A - append from end of line
o - open line(under)
O - open line(upper)
H - move to the top of the screen
L - move to the bottom of the screen
:q - quit
:q! - override and quit
:w - write
:wq - write and quit
:{num} - Go to {num}th line
2) git basic - clone, add, commit, push
# github 저장소 복제
$ git clone https://github.com/ktbaek72/first-repo.git
# 상태 보기
$ git status
# staging
$ git add main.py
# Local repo commit
$ git commit
# 변경 내용 확인 하기
$ git diff main.py
# 원격 github에 변경 내용 올리기
$ git push origin main
# 간단 log 보기
$ git lg
# LF 경고 처리
# $ git add main.py
# warning: in the working copy of 'main.py', LF will be replaced by CRLF the next time Git touches it
$ git config --global core.autocrlf false

3) github pages
# version 확인
$ node -v
v20.12.2
$ npm -v
10.5.0
# hexo update
$ npm install -g hexo-cli
# blogging : Start blogging with Hexo!
$ hexo init ghblog
# 추가 update
$ npm install
# clean
$ hexo clean
INFO Validating config
# Generate static files
$ hexo generate
# Run server
$ hexo server
# Create a new post
$ hexo new post "My First Blog"
# 현재 폴더가 Editor(vscode)에서 열림
$ code .
# clean and generate 명령을 아래와 같이 한번에 하기
$ hexo clean && hexo generate
# 블로그 테마 install
$ npm install hexo-theme-next@latest
# deploy install
$ npm install hexo-deployer-git --save
# Deploy to remote sites
$ vi _config.yml
$ hexo deploy
4) branch
# git clone
git clone {주소}
# Branch list
(local) $ git branch
(remote) $ git branch -r
(all) $ git branch -a
# Create new branch
$ git branch {branch name}
# switch to branch
$ git switch {branch name}
# Delete branch
$ git branch -D stem
# Push commits on specific branch
# 첫 push에는 remote와 local의 branch 연결(-u)이 필요
(first) $ git push -u origin stem
$ git push -u origin stem
# See the differences
$ git diff main stem
5) git flow, github flow, gitlab flow
# 파일 이름 혹은 위치 수정
$ mv a.md to b.md
# Working Directory에서 변경사항 취소하기
$ git restore {filename}
# Stage의 변경사항(blob) Working directory로 내리기
$ git reset HEAD {filename}
# staging area의 변경사항을 내림과 동시에 삭제
$ git rm -f {filename}
# 직전 commit message 수정하기
$ git commit --amend
# 이전 commit message 수정하기
==> 되도록 사용하지 말자.... 프로젝트 꼬인다.
# 잘못을 인정하고 특정시점으로 되돌리기
$ git revert --no-commit HEAD~{nums of commit}..
6) Co-work with git, github
# Issue template
## Description
한 줄로 추가할 기능 설명
디테일하게 다시 설명(사진 영상 등 자유롭게 추가 가능)
## Tasks
- [ ] Item 1
- [ ] Item 2
- [ ] Item 3
## References
- [Link text](Link addr)
# github flow with fork
- 새 Organization에서 새 repo 만들기
- 새 프로젝트 생성
- clone 하여 작업한 뒤 대상 파일 push 하기
- 팀원은 새로 만든 repo에서 issue 만들면서 작업사항 정리하기
- 팀장의 작업 시작 지시에 맞춰 fork 하고 clone 하기
- 각자의 컴퓨터에 fork한 나의 repo를 clone 하기
- 작업하기 전 branch 생성하여 작업할 것(main에서 작업 지양)
- 작업사항을 나의 repo에 push
- 팀 repo에 작업사항을 전달하기 위한 PR 열기
- PR 내용 작성한 뒤 Create pull request
- 팀장은 생성된 PR에 대해 code review를 실시
- 팀원은 code review 결과 추가 작업사항을 열려있는 branch에서 작업하기
- 추가 작업사항을 나의 PR이 열려있는 branch로 push
- 나에게 push하면 자동으로 연결됨
- 팀장은 추가 작업사항에 대해 재검토 후 Approve 로 최종 승인
다음 프로젝트부터는 git을 사용해 보자.