코딩하는 문과생
[GIT] 생활코딩, GIT4 - 협업 본문
branch와 backup 지식이 필수적.
[혼자 작업하기]
$ mkdir git_collaboration
$ git init a
$ cd a
$ nano work.txt
# 1
$ git add work.txt
$ git commit -m "work 1"
# 백업하자
# 깃헙에 우선 저장소 생성(git-collaboration-cli)
$ git remote add origin https://github.com/sijune/git-collaboration-cli.git
$ git push -u origin master
# -u: master - master 페어링이 필요
[같이 작업하기]
이제 동료가 생겼다.
- 오픈소스는 누구나 다운은 가능하지만
- 누구나 push는 불가능
-과정
settings-> collaborators & teams(권한 부여 가능(admin, write...))
- -> collaborators에 협업할 아이디 등록 -> add collaborator-> 초대된 사람에게 이메일 전송 -> view invitation -> accept invitation
- ->copy invite link
우리는 한 대의 컴퓨터로 두개의 저장소를 만들고 각 저장소를 서로 다른 사용자가 사용한다고 가정
$ git clone https://github.com/sijune/git-collaboration-cli.git b
$ cd b
[push & pull]
# ***A area***
$ nano work.txt
# 1
# 2a
$ git commit -am "work 2a"
$ git push
$ git log --all --graph --oneline
# ***B area***
$ nano work.txt
# 1
# 2b
$ git commit -am "work 2b"
$ git log --all --graph --oneline
# pull하지 않고 작업을 해버렸다.or동시에 작업하는 경우
$ git push
# ***에러 발생***
# 원격 저장소에 다른 사람이 이미 작업한 내용이 있다.
# 다른 사람이 작업한 것을 자신의 폴더로 pull해야한다.
$ git pull
# 2a와 2b가 충돌 - 에러
$ cat work.txt
$ git mergetool or nano work.txt
# 1
# 2ab
$ git add work.txt
$ git commit
$ git log --all --graph --oneline
$ git push
# ***A area***
$ git pull
$ git log --all --graph --oneline
[pull과 fetch+merge]
- pull -> commit -> push
- fetch -> merge FETCH_HEAD -> commit -> push
master: 지역 저장소 master
origin.master: 원격 저장소 master
# ***A area***
$ nano work.txt
# 1
# 2ab
# 3a
$ git commit -am "work 3a"
$ git log --all --graph --oneline (1)
# master는 work 3a를
# origin/master는 이전 commit을
$ git status
# push해라
$ git push
$ git log --all --graph --oneline (2)
# ***B area***
$ git fetch
$ git log --all --graph --oneline (3)
# origin/master가 변동된다.
$ cat work.txt
# 아직 없다.
$ git pull or git merge origin/master
$ git log --all --graph --oneline (4)
# ***git pull = git fetch; git merge origin/master(FETCH_HEAD)***
# 신중하게 결합하길 원할 때 fetch를 쓴다.
# 복잡하다면 그냥 pull
[오픈소스 참여하기 - patch]
# ***B area***"
$ nano work.txt
# 4b추가
$ git commit -am "work 4b"
$ nano work.txt
# 5b추가
$ git commit -am "work 5b"
# 권한이 없다고 가정
$ git log --all --graph --oneline
$ git format-patch 0b417983b9780a5b47bd657d5de3675528d3b790
# 마지막으로 작업한 commit id - 3a id
$ cat 0001-work-4b.patch
# 각각 버전 간 언제 누가 무엇을 작업했는지 알 수 있다.
# ***A area***
$ cp ../b/*.patch .
$ git am -3 -i *.patch
# apply mailbox, 3 way merge, interactive모드
# v(패치내용), y, e(commit 메세지), y
$ git log --all --graph --oneline
# coomit id가 다르다.
[pull request]
pull request: 내가 작업한 것을 당겨가 주십쇼.
- git이 제공하는 게 아니라 git hosting이 제공한다고 생각
- sijune/git-collaboration-cli fork를 뜰 예정
- fork를 하면 해당 원격 저장소가 본인 계정에 fork(복제)된다.
clone: 같은 원격저장소
fork: 저장소를 복제해서 내껄로 가져온다.
# ***C area***
$ git clone https://github.com/sijune-temp/git-collaboration-cli.git c
$ cd c
$ nano work.txt
# 6c추가
$ git commit -am "work 6c"
$ nano work.txt
# 7c추가
$ git commit -am "work 7c"
$ git push
# sijune-temp/git-collaboration-cli로 보낸다.
# ***sijune_temp/git-collaboration-cli 원격 저장소***
# compare: sijune/git-collaboration-cli sijune_temp/git-collaboration-cli을 비교
# create pull request: 이것을 pull해주세요
# title: pull request my work please!!!
# ***fork뜬 기존 github저장소(sijune/git-collaboration-cli)***
# request확인
# merge pull request 클릭
# confirm merge
# ***A area***
$ git pull
$ git log --all --graph --oneline
[수업을 마치며]
- gerrit - code review
- github의 issue tracker
[정말 중요한 것]
- pull-commit-psuh
- conflict
'개발 관련 지식 > GIT' 카테고리의 다른 글
[GIT] 생활코딩, GIT3 - Branch & Conflict (0) | 2019.12.13 |
---|---|
[GIT] 생활코딩, GIT3 - Backup (0) | 2019.12.13 |
[GIT] 생활코딩, GIT2 - 버전관리 (0) | 2019.12.13 |
[GIT] 생활코딩, GIT 1 (0) | 2019.12.13 |