[Git] Remote Repository

jayce·2024년 6월 17일

Remote Repository

Remote Repository

  • GitHub 에서 Remote 저장소를 생성
  • 앞에서 Git Clone 하여 사용
  • Local Repository 에서 Push, Pull (Fetch)하여 동기화
    - Pull : 팀원이 작업한 걸 공유받는 것
    - Push : 본인이 작업한 걸 공유하는 것

Remote Repository 추가

  • Local repository에 Remote Repository를 add
  • 여러개 등록 시 repository에 이름을 지정해 관리
  • deault repository : origin
  • 가장 중요한 Remote Repository는 반드시 Orgin이라는 이름 설정
git remote add <remote_repo_name><remote_repo_url>
git remote add origin <remote_repo_url>

Remote Repository 주소 수정

  • 토큰 설정 안하여 주소를 수정해야하는 경우 등
git remote set-url <remote_repo_name><remote_repo_new_url>
git remote set-url origin <remote_repo_url>

Remote Repository 이름 수정

git remote rename <old_name><new_name>

Remote Repository 삭제

git remote renove <remote_repo_name>
git remote remove origin

Remote Repository 정보 확인

  • 등록한 이름과 Url 정보 확인 가능
  • 토큰 정보를 같이 저장한 경우 토큰 정보도 확인 가능
  • ❗ 개인컴퓨터가 아닌 공용 컴퓨터에서 작업시, 토큰정보를 저장하면 토큰 유출될 수 있으니 주의!
git remote -v

Remote Repository 상세보기

  • 등록한 정보와 Url뿐 아니라 Branch정보 등 상세 정보까지 확인 가능
git remote show <remote_repo_name>
git remote show origin

Pull

  • Remote Repository 의 작업내용을 Local Repository에 동기화하기

  • git pull 만 적으면 기본으로 Remote에 있는 main과 연동되어 git pull origin main 과 동일

  • 사실 Fetch 와 Merge 의 과정

Fetch : Remote Repository의 변경사항을 Local Repository에 다운
Merge : 기존의 것과 병합

git pull <remote_repo_name><branch_name>
git pull origin main
git pull origin branch_name

Push

  • Local Repository에서 작업한 내용을 Remote Repository에 배포
git push <remote_repo_name><branch_name>
git push origin main

Local Repository

Local 저장소 생성

mkdir local_project
cd local_project
git init

비어있는 Remote 저장소 생성

  • Local Repository와 연결할 Remote Repository 생성
  • Add a README file 과 Add .gitignore 파일 생성 X

Remote 저장소 주소 & Token 복사

  • 기록해둔 토큰, 또는 잊어버렸다면 토큰 새로 발급
  • 나는 저번 시간에 발급한 Token 사용

Local 저장소에 Remote 추가

git remote add local https://github.com/user_name/local_project.git
git remote -v

Rename - 저장소 이름은 origin

git remote rename local origin
git remote -v

주소에 Token 추가

git remote set-url origin <remote_repo_new_url>
git remote -v

Local의 내용을 Remote에 Push

touch readme.md
git add readme.md
git commit -m "add readme file"
git status
git push origin main

💡 Remote 저장소에서 확인

cat >> README.md
this is push test.
git add README.md
git commit -m "push test"
git log
git push origin main

💡 Remote 저장소에서 확인

Remote Repository

Remote 저장소 생성

Local 저장소에 Clone

  • Remote Repository주소에 Token 포함시키기
  • Git Clone은 mkdir > Git init > Git Remote add > Git Pull 해줌
git clone https://<token>@github.com/<user_name>/remote_project.gite 
cd remote_project
git status

Remote 저장소 정보 확인

git remote show origin

GitHub 에서 README.md 를 수정

  • 프로젝트 화면 중 README 파일 우측에 연필 표시 선택하면 수정 가능
  • GitHub에서 수정내용을 Commit 가능
  • 우측에 Commit 누르면 Commit한 이력(변경 이력) 확인 가능 -> 버전 증가함

Local 저장소에서 Pull

git pull origin main
# 또는
git pull

Local 저장소에 GitHub의 수정이력이 반영

git log --oneline

0개의 댓글