Using source control in your codespace

After making changes to a file in your codespace you can quickly commit the changes and push your update to the remote repository.

Codespaces is available for organizations using GitHub Team or GitHub Enterprise Cloud. For more information, see "GitHub's products."

About source control in Codespaces

You can perform all the Git actions you need directly within your codespace. For example, you can fetch changes from the remote repository, switch branches, create a new branch, commit and push changes, and create a pull request. You can use the integrated terminal within your codespace to enter Git commands, or you can click icons and menu options to complete all the most common Git tasks. This guide explains how to use the graphical user interface for source control.

Source control in GitHub Codespaces uses the same workflow as Visual Studio Code. For more information, see the Visual Studio Code documentation "Using Version Control in VS Code."

A typical workflow for updating a file using GitHub Codespaces would be:

  • From the default branch of your repository on GitHub, create a codespace. See "Creating a codespace."
  • In your codespace, create a new branch to work on.
  • Make your changes and save them.
  • Commit the change.
  • Raise a pull request.

Creating or switching branches

  1. If the current branch is not shown in the status bar, at the bottom of your codespace, right-click the status bar and select Source control.
  2. Click the branch name in the status bar. The branch in the status bar
  3. In the drop-down, either click the branch you want to switch to, or enter the name for a new branch and click Create new branch. Choose from the branch menu

Tip: If someone has changed a file on the remote repository, in the branch you switched to, you will not see those changes until you pull the changes into your codespace.

Pulling changes from the remote repository

You can pull changes from the remote repository into your codespace at any time.

  1. In the Activity Bar, click the Source Control view. Source control view
  2. At the top of the side bar, click the ellipsis (...). Ellipsis button for View and More Actions
  3. In the drop-down menu, click Pull.

If the dev container configuration has been changed since you created the codespace, you can apply the changes by rebuilding the container for the codespace. For more information, see "Introduction to dev containers."

Setting your codespace to automatically fetch new changes

You can set your codespace to automatically fetch details of any new commits that have been made to the remote repository. This allows you to see whether your local copy of the repository is out of date, in which case you may choose to pull in the new changes.

If the fetch operation detects new changes on the remote repository, you'll see the number of new commits in the status bar. You can then pull the changes into your local copy.

  1. Click the Manage button at the bottom of the Activity Bar. Manage button
  2. In the menu, slick Settings.
  3. On the Settings page, search for: autofetch. Search for autofetch
  4. To fetch details of updates for all remotes registered for the current repository, set Git: Autofetch to all. Enable Git autofetch
  5. If you want to change the number of seconds between each automatic fetch, edit the value of Git: Autofetch Period.

Committing your changes

  1. In the Activity Bar, click the Source Control view. Source control view
  2. To stage your changes, click + next to the file you've changed, or next to Changes if you've changed multiple files and you want to stage them all. Source control side bar with staging button highlighted
  3. Type a commit message describing the change you've made. Source control side bar with a commit message
  4. To commit your staged changes, click the check mark at the top the source control side bar. Click the check mark icon

Raising a pull request

  1. After you've committed changes to your local copy of the repository, click the Create Pull Request icon. Source control side bar with staging button highlighted
  2. Check that the local branch and repository you're merging from, and the remote branch and repository you're merging into, are correct. Then give the pull request a title and a description. Source control side bar with staging button highlighted
  3. Click Create.

Pushing changes to your remote repository

You can push the changes you've made. This applies those changes to the upstream branch on the remote repository. You might want to do this if you're not yet ready to create a pull request, or if you prefer to create a pull request on GitHub.

  1. At the top of the side bar, click the ellipsis (...). Ellipsis button for View and More Actions
  2. In the drop-down menu, click Push.

Did this doc help you?

Privacy policy

Help us make these docs great!

All GitHub docs are open source. See something that's wrong or unclear? Submit a pull request.

Make a contribution

Or, learn how to contribute.