0%

201109_TIL(git 기초)

오늘 한 것

Git을 이용한 협업

  • git을 이용한 협업의 방법은 아래와 같다.
    1. GitHub Collaboration 하지만 추천하지 않는다.
    2. Fork 이 방법을 추천한다.

git branch

  • 마블 멀티 유니버스를 만드는 느낌으로 만들어준다!
  • $ git branch 명령어를 통해 현재 branch를 모아 볼 수 있다.
  • $ git branch {branch 이름} 명령어로 멀티유니버스를 생성해준다.
  • $ git checkout {branch 이름} 명령어는 입력한 branch로 바꾸는 명령어이다.
  • $ git merge {branch 이름} 명령어는 입력한 branch를 지금 branch로 병합하는 명령어이다.
1
2
3
4
5
~/Documents/dev/branch-practice (master)
$ git merge footer
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
  • branch 내용이 서로 달라서 conflict될 경우 merge에 실패한다. 다행히도 어떤 점이 충돌했는지 표시돼있다.
    conflict_해결

  • 둘 중 하나를 고르거나 재조합할 수 있다.

  • 작업 중인 branch는 남겨두지만 작업이 끝난 branch는 merge 후 없애는 것이 편하다.

1
2
3
4
5
6
7
~/Documents/dev/branch-practice (master)
$ git branch -D footer
Deleted branch footer (was 6163da2).

~/Documents/dev/branch-practice (master)
$ git branch -D header
Deleted branch header (was 151c663).

$ git branch -D {branch 이름}은 branch를 제거하는 명령어이다.

git flow

  • Brew 여기서 Brew 설치법을 익히고 사용해보자

flow의 시작

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
~/Documents/dev/branch-practice (master)
$ git flow init

Which branch should be used for bringing forth production releases?
- master
Branch name for production releases: [master]
Branch name for "next release" development: [develop]

How to name your supporting branch prefixes?
Feature branches? [feature/]
Bugfix branches? [bugfix/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
Hooks and filters directory? [C:/Users/ChoiYonghun/Documents/dev/branch-practice/.git/hooks]
  • git flow init을 통해 master를 포함한 branch를 만들 수 있다.
1
2
3
4
~/Documents/dev/branch-practice (develop)
$ git branch
* develop
master
  • master의 경우 최종 릴리즈에 사용한다.
  • 개발은 develop branch에서 진행하자!

flow feature

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
~/Documents/dev/branch-practice (develop)
$ git flow feature start create-sauron
Switched to a new branch 'feature/create-sauron'

Summary of actions:
- A new branch 'feature/create-sauron' was created, based on 'develop'
- You are now on branch 'feature/create-sauron'

Now, start committing on your feature. When done, use:

git flow feature finish create-sauron

~/Documents/dev/branch-practice (feature/create-sauron)
$ git branch
develop
* feature/create-sauron
master
  • $ git flow feature start {branch 이름}를 이용하여 새로운 개발을 위한 branch를 만들고 자동으로 checkout할 수 있다.

feature 없애기

  • feature 중 내용이 너무 맘에 안들어서 merge고 뭐고 때려치고 싶을 때는 간단하게 push하기 전에 그냥 branch를 삭제하면 된다!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
~/Documents/dev/branch-practice (feature/create-sauron)
$ touch sauron.html

~/Documents/dev/branch-practice (feature/create-sauron)
$ git add sauron.html

~/Documents/dev/branch-practice (feature/create-sauron)
$ git commit
[feature/create-sauron 1660b20] feat: create sauron.html
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 sauron.html

~/Documents/dev/branch-practice (feature/create-sauron)
$ ls
index.html sauron.html static/

~/Documents/dev/branch-practice (feature/create-sauron)
$ git checkout develop
Switched to branch 'develop'

~/Documents/dev/branch-practice (develop)
$ git branch -D feature/create-sauron
Deleted branch feature/create-sauron (was 1660b20).

~/Documents/dev/branch-practice (develop)
$ git branch
* develop
Master
  • 위와 같이 push하기 전에 checkout 후 편안한 마음으로 삭제해준다!
  • 이런 것이 feature의 편안함!

flow release

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
~/Documents/dev/branch-practice (develop)
$ git flow feature start test
Switched to a new branch 'feature/test'

Summary of actions:
- A new branch 'feature/test' was created, based on 'develop'
- You are now on branch 'feature/test'

Now, start committing on your feature. When done, use:

git flow feature finish test

~/Documents/dev/branch-practice (feature/test)
$ ls
index.html static/

~/Documents/dev/branch-practice (feature/test)
$ vi index.html

~/Documents/dev/branch-practice (feature/test)
$ git add index.html

~/Documents/dev/branch-practice (feature/test)
$ git commit
[feature/test ab55d8e] feat: Create aside
1 file changed, 42 insertions(+), 35 deletions(-)
rewrite index.html (92%)

~/Documents/dev/branch-practice (feature/test)
$ git flow feature finish test
Switched to branch 'develop'
Updating ec453b4..ab55d8e
Fast-forward
index.html | 63 ++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 35 insertions(+), 28 deletions(-)
Deleted branch feature/test (was ab55d8e).

Summary of actions:
- The feature branch 'feature/test' was merged into 'develop'
- Feature branch 'feature/test' has been locally deleted
- You are now on branch 'develop'

~/Documents/dev/branch-practice (develop)
$ git flow release start v0.0.1
Switched to a new branch 'release/v0.0.1'

Summary of actions:
- A new branch 'release/v0.0.1' was created, based on 'develop'
- You are now on branch 'release/v0.0.1'

Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:

git flow release finish 'v0.0.1'

~/Documents/dev/branch-practice (release/v0.0.1)
$ git branch
develop
master
* release/v0.0.1

~/Documents/dev/branch-practice (release/v0.0.1)
$ git flow release finish v0.0.1
Switched to branch 'master'
Merge made by the 'recursive' strategy.
index.html | 65 ++++++++++++++++++++++++++++------------------------
static/css/style.css | 3 +++
2 files changed, 38 insertions(+), 30 deletions(-)
create mode 100644 static/css/style.css
Already on 'master'
Switched to branch 'develop'
Already up to date!
Merge made by the 'recursive' strategy.
Deleted branch release/v0.0.1 (was ab55d8e).

Summary of actions:
- Release branch 'release/v0.0.1' has been merged into 'master'
- The release was tagged 'v0.0.1'
- Release tag 'v0.0.1' has been back-merged into 'develop'
- Release branch 'release/v0.0.1' has been locally deleted
- You are now on branch 'develop'
  1. 위와 같이 feature start를 통해 단발적인 branch를 만들어 새로운 기능을 개발한다.
  2. $ git flow feature finish {branch 이름}을 통해 종료하면 develop과 자동으로 merge 후 삭제된다.
  3. branch를 release start release finish한다.
  4. release finish를 할 때 노트가 총 세 개 열린다. 열심히 자세히 양식에 최대한 맞춰서 적어본다!
    1. master branch commit 노트
    2. release 노트 (제일 중요하다!)
    3. develop branch commit 노트
  • flow를 열심히 사용하여 협업을 잘하는 개발자가 되자!

Fork 하기!

  • 팀장의 역할

    1. repo를 만들어준다.
    2. git clone 한다.
    3. git flow init
    4. README.md 파일 등 만들기
    5. 개발개발개발개발개발
    6. git push -u origin develop //upstream set이 필요하다면!
    7. 팀원의 issue에 성심성의껏 대답하고 조율한다.
    8. 팀원이 pull request를 보낸다면 신중하게 검토한 후 merge 한다.
  • 팀원의 역할

    1. 팀장이 만든 repo를 fork한다.
    2. git clone 한다.
    3. isuue를 요청하여 작업에 대해 알리고 논의한다.
    4. `git flow feature start {branch name} //feature을 사용하자 괜히 원본 건들지말고
    5. 개발개발개발개발개발
    6. 개발이 끝났다면 내가 clone한 repo에 git push한다.
    7. 팀장에게 pull request를 보낸다.

기타

  • vim 사용시 set nu 명령어를 통해 line number를 표시할 수 있다.

오늘 느낀 것

  • git이 이렇게 복잡하다니.. 하지만 협업하는 법을 배우는 것이 즐겁다. 앞으로 진행할 협업 프로젝트에서 큰 도움이 되기를.
  • 아직 git 사용법이 서툴 다 괜한 명령어로 실수할까봐 무섭다.
  • 이번주부터 진행하는 팀 프로젝트, 공부한 것을 토대로 열심히 해보자!

Nyong’s GitHub