README.md
파일에 대하여.gitignore
.gitignore
자동화 Tool: www.gitignore.io
ls -a
로 파일 목록에서 확인 가능.gitignore
파일$ vi .gitignore
# Custom
keyfile.pem
crendentials/**
secrets.*
*.java
실습에 필요한 파일들을 생성
$ touch app.js
$ touch keyfile.pem
$ mkdir credentials
$ touch credentials/index.html
$ touch secrets.css
$ touch server.java
$ touch index.html
.gitignore
의 규칙에 부합하는 파일들은 Git이 추적하지 않는 것을 알 수 있음
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
app.js
index.html
nothing added to commit but untracked files present (use "git add" to track)
💡 tip:
.gitignore
의 prefix는conf
분기점을 생성하여 독립적으로 코드를 변경할 수 있도록 도와주는 모델
$ git branch {브랜치명}
$ git branch
* main
print-hello
$ git switch print-hello
hello.py
을 생성하고, print('hello')
를 입력 후, 저장
$ touch hello.py
$ vi hello.py
commit
하기
$ python3 hello.py
$ git status
$ git add hello.py
$ git status
$ git commmit
👉 print-hello
브랜치에서 작업했으므로 main
브랜치에는 hello.py
가 존재하지 않음
main
브랜치로 이동 후, print-hello
와 병합
$ git merge print-hello
print-hello
브랜치 삭제
$ git branch -D print-hello
💡 tip: 브랜치의 라이프사이클이 다하면 바로 제거하는 것이 좋음
repeat-hello
브랜치 생성
$ git branch repeat-hello
hello.py
를 다음과 같이 수정 후 commit
magic_num = 3
if magic_num%3==0:
print('hello')
feat: Print hello if magic_num is times of 3
repeat-hello
브랜치 이동
$ git switch repeat-hello
hello.py
를 다음과 같이 수정 후 commit
$ cat hello.py
for _ in range(1,10+1):
print 'hello'
main
브랜치로 이동하여 merge
$ git switch main
$ git merge repeat-hello
이때, main
, repeat-hello
두 브랜치에서 변화가 있었는데 병합 시 어떤 결과가 있을까?
Auto-merging hello.py
CONFLICT (content): Merge conflict in hello.py
Automatic merge failed; fix conflicts and then commit the result.
다음 이미지와 같이 hello.py
에 main
브랜치와 repeat-hello
브랜치에서 편집한 코드가 모두 있음
👉 선택 / 재조립이 필요함
두 가지의 코드를 적절히 섞어서 다음처럼 재조립 후 commit
$ cat hello.py
for i in range(1,10+1):
if i%3==0:
print('hello')
local main
->remote main
$ git push origin main
Git에서 repeat-hello
브랜치는 인식하지 못하므로 다음 이미지의 Network에 나타나지 않음(따라서 repeat-hello
브랜치에서 push
해야 Git이 인식할 수 있음!)
-u
: upstreamset(없으면 만들면 되고 같은 브랜치니까 싱크를 맞춰주세요~)
remote에 새로운 브랜치를 push
할 때엔 -u
를 붙여야 함
$ git push -u origin repeat-hello
main
-(release)-develop
-featuremain
-featureref: https://danielkummer.github.io/git-flow-cheatsheet/index.ko_KR.html
main
브랜치만 있는 채로 진행
기본 설정 그대로 진행(모두 Enter)
$ git flow init
$ git flow feature start print-world
hello.py
파일을 다음과 같이 수정 후 commit
for i in range(1,10+1):
if i%3==0:
print('{} hello'.format(i))
elif i%5==0:
print({} 'world'.format(i))
이동해서 merge
하고 삭제까지 자동으로 해주어 편리함
$ git flow feature finish print-world
Summary of actions:
- The feature branch 'feature/print-world' was merged into 'develop'
- Feature branch 'feature/print-world' has been locally deleted
- You are now on branch 'develop'
$ git flow release start v0.1
$ git flow release finish v0.1
Summary of actions:
- Release branch 'release/v0.1' has been merged into 'main'
- The release was tagged 'v0.1'
- Release tag 'v0.1' has been back-merged into 'develop'
- Release branch 'release/v0.1' has been locally deleted
- You are now on branch 'develop'
💡 버전 넘버
- 마이너 체인지: 기능의 변화(새로운 기능 추가, 삭제)가 있을 때 뒤에 있는 숫자를 바꿈(
v0.n
)- 메이저 체인지: 이전 버전에 존재하지 않는 아예 새로운 기능이 들어오는 등.. 앞에 있는 숫자를 바꿈(
vn.0
)
push
를 해야 Git이 작업한 상황을 알 수 있음
$ git push -u origin develop
$ git switch main
$ git push origin main
$ git tag
$ git push --tags
이름, 위치 바꾸는 것 모두 Rename
레포지토리 상에서 mv
를 명령어를 사용해 Git이 알고 있는 이름이나 위치를 그냥 변경하면 삭제로 인식
❌ 나쁜 예
$ mv hello.py helloworld.py
⭕ 좋은 예
$ git mv hello.py helloworld.py
💡 tip: 단순하게 파일명 수정은 prefix가
fix
working directory 상에서 변경사항을 취소하는 작업
수정한 파일 상태가 이전으로 되돌아감(커밋 단위로, 최신의 커밋으로 돌아가는 것만 지원)
$ git restore {파일명.확장자}
add
를 취소하는 작업
HEAD
최신를 의미
$ git reset HEAD {파일명.확장자}
커밋 메시지를 수정하는 작업
$ git commit --amend
커밋을 취소하는 작업
--no-commit
되돌린 마지막 상태를 한 번에 commit
..
순차적으로
$ git revert --no-commit HEAD~3..
💡 tip:
revert
는 왜 하게 되었는지commit
시 메시지(이유)를 꼭 작성해야 함
3일 동안 깃을 배우면서 실무에 어떤 식으로 적용할 수 있는지 감이 잡히지 않아 어렵고 힘들게만 느껴졌다.🥲 오늘 드디어!! 깃을 마무리 하면서 조원들과 팀장, 팀원 역할을 나누어서 직접 차근차근 해나가는 시간을 가졌다. 팀단위 깃 사용법을 익힐 수 있었고, 대단한 건 아니지만..ㅎㅎ 괜시리 뿌듯하고 즐거웠다. 특히나 우리 조가 모두 오프라인으로 나와서 함께 강의를 들어서 문제가 발생할 때마다 같이 고민하고 해결할 수 있다는 점이 정말 좋았다.