개발

Github, colab 연동

인공지능 대학생 2024. 12. 23. 11:26

1. Github repository 생성

 

2. Access token 생성

Settings > Developer Settings > Personal access tokens > github 접근 옵션 설정 후 토큰 생성

생성 된 토큰은 개인공간에 미리 복사해 두기

여기선 "Tokens (classic)"으로 진행
github password 입력 (확인용)

 

3. Colab 연동

3.1. Colab 생성 및 Google drive mount

Colab 파일 생성 후 아래 파이썬 명령어를 실행하여 Google drive를 mount 수행.

추후 Github 연동을 위한 경로도 복사해 두기 (Mount 된 Google drive 디렉토리 구조에서 마우스 우클릭 후 "경로 복사" 선택)

# 실행 (Ctrl+Enter)
from google.colab import drive
drive.mount('/content/drive')

Google drive가 mount 되었음을 확인

* 테스트에선 /content/drive/MyDrive/Colab Notebooks 에 데이터를 받고 관리할 것이므로 경로 이동

cd /content/drive/MyDrive/Colab Notebooks

 

3.2. Github repository clone

Git clone 수행 후 지정한 경로에 Repository가 생성됨을 확인

!git clone https://(username):(access token)@github.com/(username)/(repository name).git

3.3. Github commit을 위한 정보 입력

Github email, id 설정

!git config --global user.email '(user email)'
!git config --global user.name '(user name)'

 

4. 연동 Test

위 경로 하단에 신규 파일 생성 > 다시 Google drive mount > Github email, id 입력 > Git add or commit

 

- Add

!git add test_upload.ipynb

 

- Commit

!git commit -m "test upload"
!git push

 

- Github repository에서 확인

 

반응형