GitHub (1) (DAY 11~12)

코딩기록·2024년 10월 22일

기본 사용법

Remote Repo를 Local Repo로 가져오기

(1) 폴더를 저장하고자 하는 위치로 cd 이동

(2) git clone <repository_url> : main 폴더만 동기화되어 가져옴
-- 폴더 안의 파일만 가져올 때 : git clone <repository_url> . (마침표 추가)
-- 폴더명을 바꿔서 가져올 때 : git clone <repository_url> 새파일명 (새파일명 추가)

(3) 할 필요 없는 것(자동 세팅됨) :

  • git remote add <remote repo 별칭> <repository_url>

    (4) remote repo의 branch 확인 : git branch -r 혹은 git branch -a

    (5) 필요한 main 외 타 branch 불러오기
    -- 방법 두 가지 있음. 첫번째 방법 추천
    -- 1번 방법) git swtich <브랜치명(origin 제외)> 하면 자동으로 local branch 생성됨
    -- 2번 방법) git checkout <origin브랜치명> -> git branch <branch> -> git push <branch>

    (6) 새로 브랜치 만들어서 작업할 것!!!

    (7) push 할 때 : main branch에서 push 하지 말 것 + push 하고 pull request 작성할 것 -> administrater가 merge pull request

Local Repo를 Remote Repo로 가져가기

  1. 초기설정
  • Git-hub에서 Remote Repository 생성
  • Git Bash에서 Remote Repo로 가져오고자 하는 폴더로 이동
  • Remote Repo와 연결하기 : git remote add <별칭짓기(origin)> <repository_url>
    -- FYI. 로컬 git 저장소에서 원격 저장소의 연결만 끊는 방법 : git remote remove <별칭>
  • 잘 연결되었는지 확인 git remote -v or git remote show origin
  • 푸쉬 :
    (1) git push -u origin 브랜치 : 한 번 명령하면, push 하려는 branch가 동기화되어 있다는 전제 하에 다음번 부터는 git push만 해도 알아서 현재 위치해 있는(전체 브랜치가 아님) 브랜치가 git push 됨.
    (2) git push origin <branch> : 해당 branch를 push (예를 들어 main 브랜치를 push하려면, 내가 지금 feature/log-in 브랜치에 위치해 있는 상태여도 git push origin main 입력하면 main 브랜치가 push됨.

0개의 댓글