This page describes how to use version control for your application files with the Cloud Shell Editor's Git support.
Use version control
By clicking the Source Control view from the Activity bar , 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.
Authenticate 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:
- Launch the Cloud Shell Editor terminal by clicking Terminal > New Terminal.
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.
Toggle 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 panel with the context of your chosen repository.
Display working changes
As you add, modify, and delete files, these changes are reflected under the Changes section in your Source Control panel. You can choose to open the selected file, stage these changes, discard changes, or see what changes are being made in this commit.
Turn on diff view
In the Source Control panel, your changed files are listed under Changes. If you've staged your changed files, they're also listed 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.
Commit changes
When you're ready to check in your changes, you can do so right from within the Cloud Shell.
Run the following git commands using the Cloud Shell terminal:
git config --global user.email you@example.com git config --global user.name YourName
To check in your change, in the Source Control panel in the Cloud Shell Editor, write a commit message and then click Commit or press Cmd/Ctrl + Enter).
Clone a repository
To clone a remote Git repository for use in the Cloud Shell Editor:
- Retrieve the repository URL: For GitHub repositories, open the main page of your repository and then open the Clone or Download dialog.
- Launch the command palette (press
Ctrl
/Cmd
+Shift
+P
or click View > Command Palette) and then run Git: Clone. - When prompted, enter the Git repository location.
Create and switching between branches
To create a new branch or switch to working on an existing branch:
- Launch the command palette (press
Ctrl
/Cmd
+Shift
+P
or click View > Command Palette) and then run Git: Checkout. - 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.
If you don't have an upstream branch set up, the Publish action is available to push your local changes to a remote repository.