๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

TIL/Colab

Google Drive + Google Colab + GitHub ์—ฐ๋™ํ•˜๊ธฐ

๋ฐ์ดํ„ฐ ๋ถ„์„ ๊ณต๋ถ€๋ฅผ ํ•˜๋ฉด์„œ Colab์œผ๋กœ ์ฝ”๋“œ๋ฅผ ๋Œ๋ฆด ๋•Œ๊ฐ€ ๋งŽ์€๋ฐ, ์ด๋ฅผ Github์— ์˜ฌ๋ฆฌ๊ธฐ์œ„ํ•ด Google Drive์—์„œColab ํŒŒ์ผ(.ipynb)๋ฅผ ๋‹ค์šด๋ฐ›์•„ ๋กœ์ปฌ์ €์žฅ์†Œ๋กœ ์˜ฎ๊ธฐ๊ณ  git๋ ˆํผ์ง€ํ† ๋ฆฌ์— ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋ฐ”๋ณด์ง“์„ ํ•ด์˜จ ์‚ฌ๋žŒใ… ใ…  ์ € ๋ฟ์ธ๊ฐ€์š”...?

 

์ด๋Ÿฐ ๋ถˆํŽธํ•จ์„ ๊ทน๋ณตํ•˜๊ณ ์ž! Google Drive์™€ Github ๋ ˆํผ์ง€ํ† ๋ฆฌ๋ฅผ ์—ฐ๋™์„ ์‹œ๋„ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค!

์ตœ๊ทผ Github ์ธ์ฆ ๋ฐฉ์‹์ด ๋ณ€๊ฒฝ๋˜๋ฉด์„œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋งŒ์œผ๋กœ๋Š” ์—ฐ๋™์ด ๋ถˆ๊ฐ€๋Šฅํ•œ๋ฐ์š”, ๊ธฐ์กด ํฌ์ŠคํŒ…๋“ค์€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ์—ฐ๋™ํ•˜๋Š” ๋ฐฉ์‹์ด ๋งŽ์•„์„œ ํ˜„์žฌ๋Š” ์•ˆ๋˜๋Š” ๋ฐฉ๋ฒ•๋“ค์ด์—ˆ์Šต๋‹ˆ๋‹ค ใ… ใ… 

 

๊ฒฐ๊ตญ ์ €๋Š” ์ด๊ณณ์˜ ํฌ์ŠคํŒ…์„ ๋”ฐ๋ผํ–ˆ๋Š”๋ฐ์š”,

https://towardsdatascience.com/google-drive-google-colab-github-dont-just-read-do-it-5554d5824228

์˜์–ด๊ฐ€ ์–ด๋ ค์šฐ์‹  ๋ถ„๋“ค์€ ์ œ ํฌ์ŠคํŒ…์„ ์ฐธ๊ณ ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค!

1. Colab ์— ๊ตฌ๊ธ€ ๋“œ๋ผ์ด๋ธŒ ์—ฐ๋™ํ•˜๊ธฐ

from google.colab import drive
from os.path import join
ROOT = "/content/drive"
print(ROOT)
drive.mount(ROOT)

  • ํŒŒ๋ž‘์ƒ‰ ๋งํฌ์— ๋“ค์–ด๊ฐ€์…”์„œ ์ธ์ฆ ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ ์•„๋ž˜์— ๋„ฃ์–ด์ฃผ์„ธ์š”. (์•„์ฃผ ๊ฐ„๋‹จํ•˜์ฃ ?)

2. Github ๋ ˆํผ์ง€ํ† ๋ฆฌ๋ฅผ clone ํ•  Google Drive ๊ฒฝ๋กœ ์ฐพ๊ธฐ

  • ์ €๋Š” amazon-fashion-data-description-generation ์ด๋ผ๋Š” Github ๋ ˆํผ์ง€ํ† ๋ฆฌ๋ฅผ Google Drive ์† 'Github' ํด๋” ์•„๋ž˜์—amazon-fashion-data-description-generation ํด๋” ์•„๋ž˜์— clone ํ•ด์˜ค๋ คํ•ฉ๋‹ˆ๋‹ค. (๋ ˆํผ์ง€ํ† ๋ฆฌ๋ณ„๋กœ ์˜ˆ์˜๊ฒŒ ์ •๋ฆฌํ•˜๊ณ ์‹ถ์–ด์„œ!)
1. amazon-fashion-data-description-generation ํด๋” ์ƒ์„ฑ
2. amazon-fashion-data-description-generation ํด๋” ์šฐํด๋ฆญ > copy path
  • ์œ„ ๋ฐฉ์‹์œผ๋กœ ๊ฒฝ๋กœ๋ฅผ ๋ณต์‚ฌํ•ด๋‘ก๋‹ˆ๋‹ค.

3. Github Access Token ์ƒ์„ฑํ•˜๊ธฐ

Github์™€ ์—ฐ๋™์„ ์œ„ํ•ด์„œ๋Š” ๊ธฐ์กด๋ฐฉ์‹(๋น„๋ฐ€๋ฒˆํ˜ธ์ธ์ฆ) ๋Œ€์‹  Github Access Token์„ ์ƒ์„ฑํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์ฃผ์„ธ์š”.

1. ๊นƒํ—ˆ๋ธŒ ์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ setting ํด๋ฆญ
2. Developer settings ํด๋ฆญ
3. Personal access tokens ํด๋ฆญ
4. repo ์„ ํƒ์ง€ ํด๋ฆญํ•˜๊ณ , Github Access Token ์ƒ์„ฑ
5. Github Access Token ๋ณต์‚ฌ (๋ฉ”๋ชจ์žฅ์— ๊ธฐ๋กํ•ด๋‘๋Š” ๊ฒƒ์ด ์ข‹์Œ)

from os.path import join  

# path to your project on Google Drive
MY_GOOGLE_DRIVE_PATH = '/content/drive/MyDrive/Github/amazon-fashion-data-description-generation' 
# replace with your Github username 
GIT_USERNAME = "inistory" 
# definitely replace with your
GIT_TOKEN = "[๋ณต๋ถ™ํ•œ ์ธ์ฆ์ฝ”๋“œ ์—ฌ๊ธฐ์—]"  
# Replace with your github repository in this case we want 
# to clone deep-learning-v2-pytorch repository
GIT_REPOSITORY = "amazon-fashion-data-description-generation" 

PROJECT_PATH = join(ROOT, MY_GOOGLE_DRIVE_PATH)

# It's good to print out the value if you are not sure 
print("PROJECT_PATH: ", PROJECT_PATH)   

# In case we haven't created the folder already; we will create a folder in the project path 
!mkdir "{PROJECT_PATH}"    

#GIT_PATH = "https://{GIT_TOKEN}@github.com/{GIT_USERNAME}/{GIT_REPOSITORY}.git" this return 400 Bad Request for me
GIT_PATH = "https://" + GIT_TOKEN + "@github.com/" + GIT_USERNAME + "/" + GIT_REPOSITORY + ".git"
print("GIT_PATH: ", GIT_PATH)
  • GIT_TOKEN ๋ถ€๋ถ„์— ๋ณต๋ถ™ํ•œ ์ธ์ฆ์ฝ”๋“œ๋ฅผ ๋ถ™์—ฌ์ค๋‹ˆ๋‹ค.
  • MY_GOOGLE_DRIVE_PATH์—๋Š” 2๋ฒˆ๊ณผ์ •์—์„œ ๋ณต์‚ฌํ•œ ๊ฒฝ๋กœ๋ฅผ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•ด์ค๋‹ˆ๋‹ค.
  • GIT_REPOSITORY ๋ถ€๋ถ„๋„ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒํ™ฉ์— ๋งž๊ฒŒ ๋ฐ”๊พธ๋Š” ๊ฒƒ ์žŠ์ง€๋งˆ์„ธ์š”!

4. Git clone ์ง„ํ–‰

%cd "{PROJECT_PATH}"    # Change directory to the location defined in project_path
!git clone "{GIT_PATH}" . # clone the github repository

์œ„ ๊ณผ์ •์„ ์ž˜ ๋งˆ์ณค๋‹ค๋ฉด clone์ด ์ž˜ ๋˜๋Š” ๊ฑธ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • !git clone "{GIT_PATH}" ๋‹ค์Œ์— .์„ ๋ถ™์—ฌ์ฃผ๋Š” ์ด์œ ๋Š” clone์„ ํ•ด์˜ฌ ๋•Œ, ํด๋”๋ฅผ ๋‹ฌ๊ณ  ์˜ค์ง€ ์•Š๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•จ์ž…๋‹ˆ๋‹ค.
  • . ์„ ๋ถ™์ด์ง€ ์•Š์œผ๋ฉด amazon-fashion-data-description-generation ๊ฒฝ๋กœ ์•„๋ž˜์—, clone ํ•ด์˜ค๋ ค๋Š” ๋ ˆํผ์ง€ํ† ๋ฆฌ์˜ ์ด๋ฆ„์ธ amazon-fashion-data-description-generation ํด๋”๊ฐ€ ์ƒ์„ฑ๋˜๊ณ  ๊ทธ ์•ˆ์— ๋‚ด์šฉ์ด ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค.
    (์ทจํ–ฅ์— ๋งž๊ฒŒ ์„ ํƒํ•ด์ฃผ์„ธ์š”!)

[์ถ”๊ฐ€] Google Drive์—์„œ git pull, commit, push ํ•˜๊ธฐ

  • ๊ตฌ๊ธ€ ๋“œ๋ผ์ด๋ธŒ์—์„œ ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•˜๊ณ  github ๋ ˆํผ์ง€ํ† ๋ฆฌ์— ๋ฐ˜์˜ํ•˜๋ ค๋ฉด ์•„๋ž˜ ๊ณผ์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
!git config --global user.email {๋ณธ์ธ์ด๋ฉ”์ผ์ž…๋ ฅ}
!git config --global user.name {๋ณธ์ธ๊นƒํ—™์•„์ด๋””์ž…๋ ฅ}

1) git pull

!git pull

2)git add, git commit

!git add . 
!git commit -m "update from g-drive" #์ปค๋ฐ‹๋ฉ”์„ธ์ง€๋ฅผ ์ž์œ ๋กญ๊ฒŒ ์ ์–ด์ค๋‹ˆ๋‹ค.

3)git push

!git pull

๋-!