[Git] 원격저장소 관련 CLI 명령어

2022. 4. 22. 12:06Git

1. remote, push, pull

git remote add <원격저장소 이름> <원격저장소 주소>
  • 원격저장소를 등록함
  • 원겨저장소는 여러 개 등록할 수 있지만 같은 별명의 원격저장소는 하나만 가질 수 있음
  • 통상 첫번째 원격저장소를 origin으로 지정함
git remote -v
  • 원격저장소 목록을 살펴봄

 

원격저장소 등록 및 push

$ git remote add origin https://github.com/yonghwankim-dev/git_study.git

$ git remote -v

$ git push origin feat/b

 

git push 업스트림 설정 및 푸시

$ git push -u origin feat/b # push와 동시에 업스트림 저장

$ git push

 

 

2. clone

git clone <저장소주소> [새로운 폴더명]
  • 저장소 주소에서 프로젝트를 복제함
  • 새로 생길 폴더명은 생략 가능하며 폴더명을 생략하면 프로젝트 이름과 같은 이름의 폴더가 새로 생성됨
  • 저장소 주소는 꼭 원격일 필요가 없으며 로컬저장소도 git clone 명령으로 복제할 수 있음

git clone으로 로컬저장소 복제하기

$ git clone https://github.com/yonghwankim-dev/git_study.git hello-git-cli

$ cd hello-git-cli

$ git log --oneline

$ git remote -v

 

추가 commit과 push

$ git checkout feat/b

$ cd ch06_git-playground

$ echo "second" >> file1.txt #파일에 내용 한줄 추가

$ git commit -a

$ git push

$ git log --oneline -n5

 

git pull

$ cd ../../iTshirt-cat

$ git checkout feat/b

$ git log --oneline -n1

$ git pull origin feat/b

$ git log --oneline -n1

$ cd ch06_git-playground

$ cat file1.txt

 

 

References

source code : https://github.com/yonghwankim-dev/git_study
팀 개발을 위한 Git Github 시작하기, 정호영 진유림 저