Using version control with Cloud Shell Editor

This page describes how to use version control for your application files with the Cloud Shell Editor's Git support.

Using version control

By clicking the Source Control: Git view from the Activity bar Source Control icon, you can access your Git repositories (or create a new one), view existing and staged changes, and merge changes.

From here, you can stage and unstage changes, diff between the previous state and the current version of files, and commit changes, all from within the Cloud Shell Editor.

Authenticating with Git

To pull or push changes to your Git repository or clone your repository, as you do when importing a custom sample, you must authenticate with Git. If you're working with Cloud Source Repositories; however, Cloud Shell handles authentication for you automatically.

When you carry out an action that requires authentication, Git prompts you for a password. Enter a personal access token (PAT; a more secure alternative to Git passwords). For details on setting up your PAT, see the Creating a personal access token guide.

To make your workflow more efficient and avoid having to enter your PAT multiple times, turn on credential helper to allow Git to cache your PAT for 15 minutes:

  1. Launch the Cloud Shell Editor terminal by clicking Terminal > New Terminal.
  2. Run the following command:

    git config --global credential.helper cache

For more customization options like changing timeout length and specifying a local path for credential storage, see the Git Tools - Credential Storage documentation.

Toggling between multiple repositories

You can work across multiple Git repositories with the Cloud Shell Editor. To toggle between your repositories, in the Cloud Shell Editor status bar, click your repository name. From the menu, select the repository to switch your scope to.

This updates your Source Control: Git panel with the context of your chosen repository.

Repository name highlighted in the Status bar and clicked, and Cloud Shell Editor menu displayed with available repositories to switch to

Displaying working changes

As you add, modify, and delete files, these changes are reflected under the Changes section in your Source Control: Git panel. You can choose to open the selected file, stage these changes, discard changes, or see what changes are being made in this commit.

Changed files listed under the Changes section in Source Control: Git view

Turning on diff view

Within the Source Control: Git panel, your changed files are listed under Changes and if you've staged them, under Staged Changes. Clicking any of these files brings up their diff view, showing you what's changed between the previously committed state of the file and the current state.

Diff between old app.js and amended app.js with filled in commit message and staged changes visible in the tree view

Committing changes

When you're ready to check in your changes, you can do so right from within the Cloud Shell.

  1. Run the following git commands using the Cloud Shell terminal:

    git config --global
    git config --global YourName
  2. To check in your change, in the Source Control: Git panel in the Cloud Shell Editor, write a commit message and then click Commit icon Commit or press Cmd/Ctrl + Enter).

Filled in commit message and staged changes visible in the tree view

Cloning a repository

To clone a remote Git repository for use in the Cloud Shell Editor:

  1. Retrieve the repository URL: For GitHub repositories, open the main page of your repository and then open the Clone or Download dialog.
  2. Launch the Command Palette by clicking Cmd/Ctrl+Shift+P and then run Git: Clone.
  3. When prompted, enter the Git repository location.

Creating and switching between branches

To create a new branch or switch to working on an existing branch:

  1. Launch the Command Palette by clicking Cmd/Ctrl+Shift+P and then run Git: Checkout.
  2. Select from the list of branches or create a new local branch.

Git status bar

The Git status bar provides a way to keep track of your current branch and switch to another with the branch indicator. It also provides the Synchronize Changes action to check for changes between your local repository and your upstream branch. Synchronizing changes pushes local changes to your upstream branch and pulls remote changes into your local repository.

Git status bar with branch indicator showing the master branch as current and the Synchronize Changes action adjacent

If you don't have an upstream branch set up, the Publish action is available to push your local changes to a remote repository.

Git status bar with branch indicator showing the master branch as current and the Publish action adjacent