[기타]

Google Drive와 GitHub연동하기

럭키🍀 2020. 11. 30. 14:40

Google의 Colab으로 작성한 파일을 구글 드라이브에 저장하고 계속해서 Colab으로만 개발할것 같아서 

드라이브의 디렉토리를 깃헙에 연동해 관리하고자 한다.

미리 연동하는 방법을 적은 ipynb파일을 디렉토리안에 두고 colab에서 실행만 해주면 되니 정말 편하다.

 

 

Github연동소스

github 레포에 이 소스를 .ignore에 추가해놓고 사용하면 좋다

0.colab에서 구글 드라이브 마운트, path join할 패키지 import하기

from os.path import join
from google.colab import drive

ROOT='/content/drive'
drive.mount(ROOT)

0.5 디렉토리 바꾸기

!pwd
!ls /content/drive/'My Drive'/'Colab Notebooks'/[디렉토리 이름]  #경로 명 내에 띄어쓰기는 ''로 묶는다
PROJ = "/drive/'My Drive'/'Colab Notebooks'/[디렉토리 이름]"
PROJ_PATH=join(ROOT,PROJ)
import os
import sys

sys.path.insert(0, PROJ_PATH)
%cd /content/drive/'My Drive'/'Colab Notebooks'/[디렉토리 이름]
!pwd #처음 pwd때와 다른 디렉토리로 옮겨와 있겠지

 

1.github에 레퍼지토리 있을경우 clone하기

!git clone https://github.com/[깃허브 레포 이름]

 2. 혹은 initialize하고 github의 새로운 레퍼지토리와 연결하기

!git init

3.global username과 email 설정하기-매번 해야한다

!git config --global user.email "[email주소]"
!git config --global user.name "[설정할 username]"

4.파일 추가하기

!ls
!git add [추가할 파일 명] 
!git status #상태 확인하기
!git reset #추가한 것을 되돌릴 일이 있다면

5. 커밋하기

!git commit -m "intial commit"

6.(최초시)리모트

!git remote add origin https://username:password@github.com/username/reponame.git
이때 만약 “fatal: remote origin already exists” 라는 에러메시지가 뜨면 기존 remote를 제거하고 다시 설정합니다.
!git remote rm origin
!git remote add origin https://[username:password@github.com/username/reponame.git]

7.마지막으로 push

!git push -u origin master

 

로컬에서 하는것과 마찬가지로 드라이브에서 github을 사용할 수 있다니 좋다.

특히 colab에서만 작업한다면 더욱더!

'[기타]' 카테고리의 다른 글

OS 요리사 비교  (0) 2023.09.12