1. 학습 목표
Colab에서 git clone 하는 방법
- Public repo git clone 방법
- Private repo git clone 방법
- repo에서 일부만 가져오는 법
2. 학습 내용
[1] Colab에서 public repository git clone 하는 방법
!git clone (URL)
이런식으로 앞에 느낌표만 붙이고 그냥 하면 됩니다.
[2] Colab에서 private repository git clone 하는 방법
Colab에서 private repo를 클론해오려고 하면?
터미널에서 클론해올 때와 달리 id와 토큰을 입력하라고 뜨지 않아요.
바로 실패합니다. 그럼 어떻게 할 수 있느냐!?
# (URL) = https://github.com/userid/repo.git 라고 하면
!git clone https://ID:토큰@github.com/userid/repo.git
기존 URL에서 https:// 와 github 사이에 ID:토큰@을 삽입하시면 됩니다.
예를 들어 github 아이디가 sweet, 토큰이 (사실 엄청 길지만ㅎㅎ) potato라고 하면
sweet:potato@를 삽입해주면 됩니다.
[3] Colab에 repository에서 일부만 git clone 하는 방법
# repo라는 repository의 main branch에서 iwantit 이라는 하위 폴더만 가져오고 싶을 때
!git init
!git config core.sparseCheckout true
!git remote add -f origin https://ID:토큰@github.com/userid/repo.git
!echo iwantit > .git/info/sparse-checkout
!git pull origin main
[4] 예제
GitHub - AlexeyAB/Yolo_mark: GUI for marking bounded boxes of objects in images for training neural network Yolo v3 and v2
GUI for marking bounded boxes of objects in images for training neural network Yolo v3 and v2 - GitHub - AlexeyAB/Yolo_mark: GUI for marking bounded boxes of objects in images for training neural n...
github.com
위의 것들을 차례로 AlexeyAB의 Yolomark를 코랩에 git clone 한다고 생각하고 따라해볼게요!
왜 하필 저거냐! 지금 생각나는 게 저거라서! ㅋㅋ
!git clone https://github.com/AlexeyAB/Yolo_mark.git
# id = sweet, token = potato
!git clone https://sweet:potato@github.com/AlexeyAB/Yolo_mark.git
* public에 id와 token 적어주셔도 당연히 잘 clone 되겠죠? ^ㅁ^
# id : sweet / token : potato / 가져 올 하위 폴더 : x64/Release
!git init
!git config core.sparseCheckout true
!git remote add -f origin https://sweet:potato@github.com/AlexeyAB/Yolo_mark.git
!echo x64/Release > .git/info/sparse-checkout
!git pull origin master
이때 main 대신 master를 사용한 이유는,
이번엔 main이 아니라, master branch를 가져올 것이기 때문입니다. ^_^**
이건 tmi인데, github에서 예전엔 기본이 master branch였는데 main으로 바뀐지 얼마 안 되었어요!
그래서 과거에 적힌 것들은 master인 경우가 꽤 있답니다.
컴퓨터에서 git을 사용할 경우 master로 생기기도 하구요,,, ㅎㅎ
GitHub - github/renaming: Guidance for changing the default branch name for GitHub repositories
Guidance for changing the default branch name for GitHub repositories - GitHub - github/renaming: Guidance for changing the default branch name for GitHub repositories
github.com
이건 깃허브가 master를 main으로 바꾼 이유에 관한 공식 문서인데요
취지가 너무 좋고 공감되기 때문에.. 혹시 git을 사용하게 되면
저도 master를 main으로 꼭꼭 바꾼 후에 이용하고 있답니다. :D
그럼 2만!