Branch를 사용하면 같은 소스코드를 각자의 독립적인 작업 영역에서 원하는 대로 수정할 수 있다. 다른 사람의 브랜치의 영향을 받지 않으며 동시에 같은 소스코드로 작업을 할 수 있다.
0. Repo Fork (옵션) (협업의 경우) 메인 Repo 내 Repo로 복제
github의 fork 버튼을 눌러서 간단하게 수행할 수 있다.
1. Master Repo Clone
git clone [url]
master repository를 내 local 저장소로 clone해온다.(복제) clone한 폴더 내에서 git branch 하는게 안정적.
<Git fork와 clone의 차이점은 아래 게시글 참고>
Git fork와 clone 의 차이점
Forking a Repository - How to Use Git and GitHub 내용을 참고했습니다. fork fork는 다른 사람의 Github repository에서 내가 어떤 부분을 수정하거나 추가 기능을 넣고 싶을 때 해당 respository를 내 Github repository로
velog.io
2. 내가 위치한 branch 확인
git branch
git branch -r #remote branch 목록 보기
3. branch 생성
git branch jihee
4. 생성한 branch로 이동
git checkout jihee
5. Push
git push --set-upstream origin jihee
git push #이후에
local의 branch를 remote branch와 연동하는 작업.
처음부터 git push를 하게 되면 아래의 메세지가 뜬다.
fatal: The current branch jihee has no upstream branch.
To push the current branch and set the remote as upstream, use git push --set ...
- git push --set-upstream origin jihee
원격 저장소에 push를 할 것인데, origin 저장소의 jihee 브랜치를 기본 브랜치로 설정할 것이라는 뜻이다.
- 이후엔 git push만 하면 된다.
<git push와 commit의 차이점은 아래 게시글 참고>
https://www.daleseo.com/git-push/
git push 사용법/팁
Engineering Blog by Dale Seo
www.daleseo.com
!주의
branch 폴더 안에 실수로 다른 repository clone하지 않기..
!업데이트
fork를 한 경우에는 이미 repo가 나뉘어 있어서, 나만 사용하는 경우 굳이 새로운 branch를 만들지 않아도 된다.
즉, clone된 내 local 저장소에서 그냥 main branch 사용하면 됨.
fork를 한 경우 origin을 pull, merge 방법은 이어지는 글을 보면 된다. (아래 글)
[git] Forked repo에서 origin repo pull하기
협업을 하며 origin repo를 내 remote repo로 fork해오고, local으로 clone해서 작업했다. 그 후 origin repo의 내용이 변경되어 local으로 pull을 해야 하는 상황이 왔다. 1. upstream remote repo 정의 먼저 for..
jiheek.tistory.com
'git' 카테고리의 다른 글
[git] git status, staging area (0) | 2022.03.21 |
---|---|
[git] Fork 협업 플로우 (0) | 2022.03.21 |
[git] Forked repo에서 origin repo pull하기 (0) | 2022.03.08 |
[git] .gitignore 파일/폴더 ignore하기 (0) | 2022.03.04 |
[git] reset으로 commit 삭제하고 복구하기 (0) | 2022.03.04 |