[Github] fork, remote, pull request git 협업 및 스터디 방법

Nam_JU·2023년 7월 23일
1

ErrorLog

목록 보기
25/26

upstream 레포와 fork 레포 명령어 정리가 필요해서 해당 게시글을 작성



협업 순서


1. git organization 생성

2. 작업할 repository 생성

3. 조원들은 해당 레포를 fork하여 개인 repository를 만든다

  • git organizaion repository
  • my fork repository

📍 로컬 저장소에 원본 Upstream 저장소 등록

$ git remote -v

위의 명령어를 치면 fork한 내 개인 repo 주소가 나옴

 ~/PycharmProjects/PythonBook_py/ [main] git remote -v
origin  https://github.com/Jupiter-J/PythonBook_py.git (fetch)
origin  https://github.com/Jupiter-J/PythonBook_py.git (push)

원격 저장소[upstream]을 연결하기 위해 해당 명령어를 친다

$ git remote add upstream [원격 저장소 주소]

git remote -v로 upstream이 생성된것을 확인

 ~/PycharmProjects/PythonBook_py/ [main] git remote add upstream https://github.com/Python-Algorithm-Study/PythonBook.git
 ~/PycharmProjects/PythonBook_py/ [main] git remote -v                                                                   
origin  https://github.com/Jupiter-J/PythonBook_py.git (fetch)
origin  https://github.com/Jupiter-J/PythonBook_py.git (push)
upstream        https://github.com/Python-Algorithm-Study/PythonBook.git (fetch)
upstream        https://github.com/Python-Algorithm-Study/PythonBook.git (push)

원본 저장소 upstream 저장소가 가진 commit 내역을 불러오기

git fetch --all


📍 Fork한 저장소 동기화

$ git fetch upstream

원본 저장소의 최신 내용을 가져온다

$ git checkout main
$ git merge upstream/main


4. 개인 레포에서 코드 수정

 $ git add .
 $ git commit -m "[커밋내용]"   
 $ git push origin main 


5. 변경된 내용을 push한뒤 pr을 생성한다

  • 개인 레포에서 pr 생성
  • 원본 저장소 upstream 레포 pullrequests에 가보면
    내가 날린 PR확인이 가능하다

6. 조원들의 PR을 merge함

위의 PR에 들어가서 Merge를 하면 upstream 레파지토리에 해당 내용들이 반영된다.

  • closed에 들어가면 merge한 내역들을 볼 수 있다


📍remote 동기화전 파일수정으로 깃이 꼬였을때

upstream 저장소의 코드를 동기화시키지 않고 파일 수정 + 커밋을 날려버렸다. 이걸 잊고 커밋내역이 남은 채로 동기화를 시켰더니 해당 오류가 나옴

 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/Jupiter-J/PythonBook_py.git'

깔끔하게 나의 로컬을 현재 깃허브(upstream)상태로 덮어씌우고 싶을때 사용하는 명령어 (대신 내 작업 내용(로컬작업)이 날라갈수 있음)

$ git reset --hard origin/<branch_name>

위의 명령어를 치니 upstream동기화전에 날린 커밋이 보임
해당부분이 없어졌다



참고자료

https://seungwubaek.github.io/tools/git/contributing_using_pull_request/
https://velog.io/@jisubin12/Github-외부저장소-fork-pull-request-동기화-하기

profile
개발기록

1개의 댓글

comment-user-thumbnail
2023년 7월 23일

좋은 글 감사합니다.

답글 달기