1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GASのコードをGitを使って管理しよう

1
Last updated at Posted at 2026-05-12

概要

GASのコードをGitで管理する方法を簡単にまとめます

前提

  • 筆者はpnpmを利用
  • 管理したいGASのプロジェクトがオンライン上に存在していること
  • リモートリポジトリが作成されていること

方法

初期構築

  1. 下記を実行してclaspをグローバルにインストールします

    pnpm add -g @google/clasp
    
  2. 今後リポジトリルートとなる任意のディレクトリを作成し、カレントディレクトリをそのディレクトリに移動します

  3. 下記を実行してclaspにログインします

    clasp login
    
  4. 下記を実行してGASのコードをローカルにクローンします(スクリプトIDはGASプロジェクトのURLのscript.google.com/home/projects/XXXXXXX/editXXXXXXXの部分です)

    clasp clone <スクリプトID>
    
  5. 下記を実行してローカルリポジトリを初期化します

    git init
    
  6. 下記を実行して初回コミットを行います

    git commit --allow-empty -m "Initial commit"
    
  7. 下記を実行してリモートリポジトリとの紐づけを行います

    git remote add origin リポジトリURL
    
  8. 下記を実行してリモートリポジトリにプッシュします

    git push origin main
    
  9. 下記を実行して現状の差分をステージします

    git add .
    
  10. 下記を実行して差分をコミットします

    git commit
    
  11. 下記を実行してコミットをリモートリポジトリにプッシュします

    git push origin main
    

運用

  • ローカルでコードを修正後下記を実行してGASにpushします※1

    clasp push
    
  • オンライン上のコードを下記を実行してローカルに取得します

    clasp pull
    

※1・・・pull後でも初めてpushする場合は下記の手順を踏む必要があります。

  1. https://script.google.com/home/usersettingsにアクセス

  2. 「Google Apps Script API」をクリック

    CleanShot 2026-05-15 at 13.43.13@2x.png

  3. スライダーをクリックして「オン」に設定

    CleanShot 2026-05-15 at 13.45.30@2x.png

注意

GAS上にハードコーディングしているWebhookのURLなどをGitに上げないように注意しましょう。
セキュアな値はスクリプトプロパティを利用しましょう。(GASのコード → 左サイドバーの歯車マーク → 下にスクロール → 「スクリプト プロパティを編集」をクリック)

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?