안녕하세요 늑대양입니다 :)
git 특강이 오늘과 내일, 2일간 진행됩니다!
오늘은 [AI 데이터 사이언티스트 취업 완성 과정]의 22일차 일과를 정리하여 안내해드리도록 하겠습니다.
Day 22 시간표:
- 오프라인 강의: git 특강
- 오프라인 강의: git 특강
git, github
강사님 소개:
- 최우* 강사님
- 전기전자공학과 전공
- disceptio 공동대표 및 플랫폼 개발
- 기업교육 : 미래엔, KB 국민카드 개발 입문과정
- 컴퓨터 사이언스 익스텐션 SCHOOL 진행
- 데이터 사이언스 SCHOOL 진행
- 프론트엔드 개발 SCHOOL 진행
Goal:
- 코드 관리를 위한 git의 정확한 사용법을 이해한다.
- git의 저장소 개념을 이해하고, 원격 저장소 서비스의 차이를 인식한다.
- git을 사용하면서 발생하는 다양한 상황을 해결할 수 있다.
- commit의 보편적인 작성법을 이해하고 이를 활용하여 commit을 작성할 수 있다.
- git의 branch model을 활용해 능숙하게 코드관리할 수 있다.
- git의 다양한 branch 전략을 이해하고 널리 사용되는 github flow 전략을 활용하여 프
- 로젝트를 수행할 수 있다.
- github projects와 issue로 프로젝트 이슈를 관리할 수 있다.
- git으로 타인과 협업하며, 다른 프로젝트에 기여할 수 있다.
Prerequisite:
For Windows:
- git for windows(https://gitforwindows.org/)
For linux, MacOS:
- git(installed)
Recap - Linux command
# pwd
# 현재 작업 디렉토리 확인 명령어
pwd
# List Segment
# 경로 내 파일 확인 명령어
ls
ls -a
ls -al
# Change Directory
# 작업 디렉토리 변경 명령어
cd
cd ~
cd <folder_name>
cd ..
cd .
cd ../..
cd ./
# MaKe DIRectory
# 디렉토리 생성 명령어
mkdir <folder_name>
mkdir .<hidden_folder_name>
# 새로운 파일 만들기
## 텍스트 기반의 파일만 생성가능
touch
touch README.md
touch main.py
# 파일 이동 및 파일 이름 변경
mv <이동하고_싶은_파일> <이동할_위치>
mv <이름을_바꾸고_싶은_파일> <바꾸고_싶은_파일_이름>
# 복사 명령어
cp
cp <원본_파일> <복사할_파일_경로_및_이름>
cp test.txt test_copy.txt
# 파일 삭제하기
rm
rm test_copy.txt
# 폴더 삭제하기
rm -r
# 폴더 및 파일 강제 삭제
rm -rf
Recap - Vim command
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
Command mode:
# 기본적으로 파일을 열면 노멀 모드
i - insert mode
:q - quit
:q! - quit discarding all changes
:w - write
:wq - write and quit
:{number} - jump to {number}th line.
Bonus - Markdown:
## Vim modes
- Normal mode: press esc on any mode.
- Insert mode: press i on normal mode.
- Visual mode: press v on nrmal mode.
- Command mode: press : on normal mode.
## How to use markdown
(heading tesxt `<h1>~<h6>`)
# #1
## #2
### #3
#### #4
##### #5
###### #6
(unordered list `<ul><li></li></ul>`)
(ordered list `<ol><li></li></ol>`)
1. `$ vi {fiename}`
2. Press `i`
3. Do work
This is paragraph1.
(`<p></p>`)
## Code highlight
This is how to `Emphasize` some text.
`Some text`
```python
def hello():
return "hello"
if __name__=='__main__':
result = hello()
print(result)
```
### Link.
`<a href="https://www.google.com/">Go to google</a>`
[Go to google](https://www.google.com/)
### Image.
`<img src="rabbit.png" alt="The rabbit is sitting on the chair">
![The rabbit is sitting on the chair](rabbit.png)`
Markdown 적용 README.md URL: https://github.com/sainthm/MGS_AI_DS/tree/main/git/dev
Bonus - Markdown 2:
<!-- 주석표기 -->
<!-- 제목 텍스트 -->
# h1
## h2
### h3
#### h4
##### h5
###### h6
<!-- 순서 없는 리스트(- * + 혼용 가능) -->
- Item1
- Item-1
- Item1-1-1
* Item2
+ Item3
<!-- 순서 있는 리스트 -->
1. Item1
2. Item2
<!-- 하이퍼링크 -->
[링크 텍스트](링크 URL)
<!-- 이미지 -->
![대체 텍스트](이미지 URL)
<!-- 강조 표기 -->
*Italic*
**Bold**
~Line Break~
_Single unserscore_
<!-- 인용문(Blockquote) -->
> 인용할 문장
<!-- Code 입력(문장 내) -->
This is how `code` works.
<!-- Code 입력(블록) -->
` ``` `
def say_hello():
return "hello"
` ``` `
<!-- 수평선 -->
Page 1
***
Page 2
-----
Page3
Use Vim in real world!
Vim adventure main URL: https://vim-adventures.com/
Vimium URL: https://chrome.google.com/webstore/detail/vimium/dbepggeogbaibhgnhhndojpepiihcmeb?hl=en
vs code vim extension URL: https://github.com/VSCodeVim/Vim
intellij vim plugin URL: https://plugins.jetbrains.com/plugin/164-ideavim
VCS (Version Control System)
== SCM (Source Code Management)
< SCM (Software Configuration Management: 형상관리)
git by Linus Torvalds:
- BitKeeper의 이용약관 위반으로 라이센스 제한에 화가 나 2주만에 만든 분산형 버전관리시스템
- 압도적 업계 1위(https://insights.stackoverflow.com/survey/2021#section-most-popular-technologies-other-tools)
- 단순한 구조와 빠른 속도
- git official repo(https://github.com/git/git)
Characteristics of git:
- 빠른속도, 단순한 구조
- 분산형 저장소 지원
- 비선형적 개발(수천개의 브랜치) 가능
Pros of git:
- 중간-발표자료_최종_진짜최종_15-4(교수님이 맘에들어함)_언제까지??_이걸로갑시다.ppt
- 소스코드 주고받기 없이 동시작업이 가능해져 생산성이 증가
- 수정내용은 commit 단위로 관리, 배포 뿐 아니라 원하는 시점으로 Checkout 가능
- 새로운 기능 추가는 Branch로 개발하여 편안한 실험이 가능하며, 성공적으로 개발이 완료되면 Merge하여 반영
- 인터넷이 연결되지 않아도 개발할 수 있음
git GUI Clients:
- git GUI
- sourcetree
- kraken
- smartGit
CLI first:
- Source code를 Cloud Platform에서 사용할 경우, CLI 커맨드로 버전관리를 수행해야합니다.
- CLI 커맨드로 git을 사용할 줄 알면, GUI 도구가 제공하는 기능에 대한 이해가 빠릅니다.
- 확인용도로 GUI를 참고하는 것은 Good^^
git objects:
- Blob: 파일 하나의 내용에 대한 정보
- Tree: Blob이나 subtree의 메타데이터(디렉토리 위치, 속성, 이름 등)
- Commit: 커밋 순간의 스냅샷
git Process Flow and Command:
git is not equal to github:
Cloud Remote Repository Services:
- Github: 비영리였던, Microsoft에 인수된 가장 유명한 서비스
- Bitbucket: Atlassian이 서비스. jira, confluence, trello 등의 부가도구와 유기적
- GitLab: GitLab이 서비스. 사설 서버 구성이 가능
Before Start:
github main URL: https://github.com/
# git version 확인
git -v
>git version 2.37.2
# git 환경설정
git config --global user.name "당신의유저이름"
git config --global user.email "당신의메일주소"
git config --global core.editor "vim"
git config --global core.pager "cat"
# 환경설정 확인
git config --list
# 수정이 필요한 경우, vim ~/.gitconfig 에서 수정 가능
# Sign up github
# Main URL: https://github.com/
# Repo clone
# Test file 생성
# git 상태 확인
git status
# Test 파일을 staging 단계로 올리기
git add <Test 파일>
# Metadata 생성
git commit
# Commit 메시지 작성
# 제목 과 내용 사이에는 엔터 두번!
# Remote repo로 전달
# git push origin main
git push
# github 로그인 작업진행
# Test file(hello.py) 수정
# git 상태 확인
git status
>현재 브랜치 main
브랜치가 'origin/main'에 맞게 업데이트된 상태입니다.
커밋하도록 정하지 않은 변경 사항:
(무엇을 커밋할지 바꾸려면 "git add <파일>..."을 사용하십시오)
(use "git restore <file>..." to discard changes in working directory)
수정함: ../../../git/dev/first-repo/hello.py
커밋할 변경 사항을 추가하지 않았습니다 ("git add" 및/또는 "git commit -a"를
사용하십시오)
# git commit 및 push 작업 진행
# git 로그 확인 명령어
git log
git과 관련된 conventional commits:
Reference URL: https://www.conventionalcommits.org/ko/v1.0.0/
- commit의 제목은 commit을 설명하는 하나의 구나 절로 완성!!
- importanceofcapitalize Importance of Capitalize
- prefix 꼭 달기!!
- feat: 기능 개발 관련
- fix: 오류 개선 혹은 버그 패치
- docs: 문서화 작업
- test: test 관련
- conf: 환경설정 관련
- build: 빌드 관련
- ci: Continuous Integration 관련
commit 할 때 기억해야 할 것:
- commit은 동작 가능한 최소단위로 자주 할 것
- 해당 작업단위에 수행된 모든 파일 변화가 해당 commit에 포함되어야 함
- 모두가 이해할 수 있는 log를 작성할 것
- Open Source Contribution시 영어가 강제되지만, 그렇지 않을 경우 팀 내 사용 언어를 따라 쓸 것
- 제목은 축약하여 쓰되(50자 이내), 내용은 문장형으로 작성하여 추가설명 할 것
- 제목과 내용은 한 줄 띄워 분리할 것
- 내용은 이 commit의 구성과 의도를 충실히 작성할 것
Conventional Commits - example:
Commit Convention은 팀마다 다를 수 있으니 관련 문서를 참조할 것
feat: Add server.py
fix: Fix Typo server.py
docs: Add README.md, LICENSE
conf: Create .env, .gitignore, dockerfile
BREAKING CHANGE: Drop Support /api/v1
refactor: Refactor user classes
README.md
- 프로젝트와 Repository를 설명하는 책의 표지와 같은 문서
- 나와 동료, 이 repo의 사용자를 위한 문서
README.md 편집 실습:
# first-repo
# README.md
이 repoistroy의 프로젝트에 대한 설명을 한 줄로 작성
Demo: [https://www.google.com/](https://www.google.com)
## Index
- Installation
- How to start
- Stacks & Skills
- Features
## Installation
```shell
$ pip install -r requirements.txt
```
## How to start
```shell
$ python main.py
or
$ jupyter notebook
```
```python
def print_hello():
return 'hello'
if __name__=='__main__':
print(hello()
```
## Stacks & Skills
- Python
- Pandas
- Numpy
- lxml
- requests
- selenium
## Features
- 키워드 기반의 각 포털 검색결과 수집
- 상위 50개의 게시물 변화 추적(단위시간별)
.gitignore
- .gitignore 는 git이 파일을 추적할 때, 어떤 파일이나 폴더 등을 추적하지 않도록 명시하기 위해 작성!
- 해당 문서에 작성된 리스트는 수정사항이 발생해도 git이 무시
- 특정 파일 확장자를 무시하거나 이름에 패턴이 존재하는 경우, 또는 특정 디렉토리 아래의 모든 파일을 무시 가능!
.gitignore 참고 사이트 URL: https://www.toptal.com/developers/gitignore
# .gitignore 파일 예시
# conf: Create .gitignore
############
#git .ignore
############
.DS_Store
*.pem
*.zip
__pycache__
.ipynb_checkpoints
License:
오픈소스 프로젝트에서 가장 중요한 license는 내가 만들 때에도, 배포할 때에도 가장 신경써 야 하는 일 중 하나!
가장 많이 사용하는 license는 다음과 같습니다!
MIT License:
MIT에서 만든 라이센스로, 모든 행동에 제약이 없으며, 저작권자는 소프트웨어와 관련한 책임에서 자유롭다!
Apache License 2.0:
Apache 재단이 만든 라이센스로, 특허권 관련 내용이 포함되어 있다!
GNU General Public License v3.0:
가장 많이 알려져있으며, 의무사항(해당 라이센스가 적용된 소스코드 사용시 GPL 을 따라야 함)이 존재!
Deal with .ipynb
- ipynb 버전트래킹을 위해 connect 가능! Main URL: https://www.reviewnb.com/
- .ipynb(jupyter notebook)은 json 기반이기 때문에 source control이 쉽지 않음
- extension 으로 극복
- 또는 https://github.com/jupyter/nbconvert 으로 .py or .html 로 변환
git은 습관이 가장 중요!
TIL:
- TIL(Today I Learned..) repository를 만들고 매일 학습하거나 얻은 지식을 정리
- commit을 쌓아 commit 하는 습관도 기르고, 나중에 찾아보기 쉬움!
Github blog:
- hexo + {username}.github.io repository로 정적 블로그를 만들어 정리하는 습관을 만들고 Markdown과 친해짐!
TIL, Github blog는 github을 이용하여 개인적으로 관리 추천!
Branch:
- 분기점을 생성하여 독립적으로 코드를 변경할 수 있도록 도와주는 모델
Branch 실습:
# branch 테스트를 위해 repo 생성
# repository name: branch-practice
# repo 생성 후, clone
git clone <repo 주소>
# 작업 디렉토리 이동
cd ./branch-practice
# 테스트 파일 생성
touch hello.py
# 테스트 파일 수정
vim hello.py
print("Hello")
:wq
# 테스트 파일 출력
python3 hello.py
>Hello
# git 상태 확인
git status
현재 브랜치 main
브랜치가 'origin/main'에 맞게 업데이트된 상태입니다.
추적하지 않는 파일:
(커밋할 사항에 포함하려면 "git add <파일>..."을 사용하십시오)
hello.py
커밋할 사항을 추가하지 않았지만 추적하지 않는 파일이 있습니다 (추적하려면 "git
add"를 사용하십시오)
# git add 작업
git add hello.py
# commit 작업
git commit
feat: Create hello. py
on branch main
# 변경 사항에 대한 커밋 메시지를 입력하십시오. '#' 문자로 시작하는
# 줄은 무시되고, 메시지를 입력하지 않으면 커밋이 중지됩니다.
#
# 현재 브랜치 main
# 브랜치가 'origin/main'에 맞게 업데이트된 상태입니다.
#
# 커밋할 변경 사항:
# 새 파일: hello.py
#
>[main 83164dc] feat: Create hello. py
1 file changed, 1 insertion(+)
create mode 100644 hello.py
# push 작업
git push
오브젝트 나열하는 중: 4, 완료.
오브젝트 개수 세는 중: 100% (4/4), 완료.
Delta compression using up to 8 threads
오브젝트 압축하는 중: 100% (2/2), 완료.
오브젝트 쓰는 중: 100% (3/3), 303 bytes | 303.00 KiB/s, 완료.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/sainthm/branch-practice.git
5627200..83164dc main -> main
# branch 작업
git branch
* main
(END)
# world branch 생성
git branch world
# branch 확인 명령어
git branch
>
* main
world
(END)
# branch 전환 명령어
git checkout world
>'world' 브랜치로 전환합니다
git switch world
>'world' 브랜치로 전환합니다
# branch 확인!
git branch
main
* world
(END)
# world 브랜치에서 hello.py 파일 수정
vim hello.py
print("Hello, world!")
:wq
# status
git status
>현재 브랜치 world
커밋하도록 정하지 않은 변경 사항:
(무엇을 커밋할지 바꾸려면 "git add <파일>..."을 사용하십시오)
(use "git restore <file>..." to discard changes in working directory)
수정함: hello.py
커밋할 변경 사항을 추가하지 않았습니다 ("git add" 및/또는 "git commit -a"를
사용하십시오)
# add
git add hello.py
# commit
git commit
feat: Replae string on hello.py
"Hello" -> "Hello, world!"
on branch world.
# 변경 사항에 대한 커밋 메시지를 입력하십시오. '#' 문자로 시작하는
# 줄은 무시되고, 메시지를 입력하지 않으면 커밋이 중지됩니다.
#
# 현재 브랜치 world
# 커밋할 변경 사항:
# 수정함: hello.py
#
>[world c5ddccd] feat: Replae string on hello.py
1 file changed, 1 insertion(+), 1 deletion(-)
git status
>현재 브랜치 world
커밋할 사항 없음, 작업 폴더 깨끗함
# branch 변경
git checkout main
'main' 브랜치로 전환합니다
브랜치가 'origin/main'에 맞게 업데이트된 상태입니다.
# 테스트 파일 확인
cat hello.py
>print("Hello")
# Merge 작업 진행!
git merge world
>업데이트 중 83164dc..c5ddccd
Fast-forward
hello.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
# 브랜치 확인
git branch
* main
world
(END)
# 테스트 파일 확인!
cat hello.py
print("Hello, world!")
Branch 실습 2:
# 실습 2 작업 히스토리 명령어
history
2316 git branch repeat
2317 git checkout repeat
2318 clear
2319 ls
2320 vim hello.py
# hello.py
# for i in range(5):
# print("Hello, world!")
2321 python3 hello.py
# Hello, world!
# Hello, world!
# Hello, world!
# Hello, world!
# Hello, world!
2322 git status
2323 git commit -am "Edit file"
2324 git push
2325 clear
2326 git checkout main
2327 git merge repeat
2328 clear
2329 ls
2330 cat hello.py
2331 git branch
긴 글 읽어주셔서 감사합니다 :)
'AI > [부트캠프] 데이터 사이언티스트 과정' 카테고리의 다른 글
[Megabyte School : AI 데이터 사이언티스트 취업 완성 과정] Day 24. (2) | 2022.09.26 |
---|---|
[Megabyte School : AI 데이터 사이언티스트 취업 완성 과정] Day 23. (2) | 2022.09.23 |
[Megabyte School : AI 데이터 사이언티스트 취업 완성 과정] Day 20. (0) | 2022.09.20 |
[Megabyte School : AI 데이터 사이언티스트 취업 완성 과정] Day 19. (0) | 2022.09.19 |
[Megabyte School : AI 데이터 사이언티스트 취업 완성 과정] Day 18. (2) | 2022.09.16 |