You can perform all the Git actions you need directly within your codespace. For example, you can fetch changes from a 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.
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 for a repository
."
- In your codespace, create a new branch to work on.
- Make your changes and save them.
- Commit the change.
- Raise a pull request.
Note:
By default, GitHub Codespaces uses the HTTPS protocol to transfer data to and from a remote repository, and authenticates with a
GITHUB_TOKEN
configured with read and write access to the repository from which you create the codespace. If you're having issues with authentication, see "
Troubleshooting authentication to a repository
."
To create a codespace for a repository for which you only have read access, you must have permission to fork the repository.
You do not need to fork the repository before you create the codespace. For example, you can create a codespace from the repository to look at the project and make experimental changes, then delete the codespace if you no longer need it.
If you make a commit from the codespace, or push a new branch, GitHub Codespaces either creates a fork of the repository under your account and links it to your codespace, or it links your codespace to an existing fork if you already have one for the repository. You can then push your changes to the fork and create a pull request to propose the changes to the upstream repository.
If you make a commit from the command line, you will see a prompt asking if you would like to proceed with linking your codespace to a new or existing fork. Enter
y
to proceed. If you commit changes from the
Source Control
view in VS Code, or from the navigation bar in a JetBrains IDE, your codespace is automatically linked to a fork without you being prompted.
Notes:
- If you delete your fork repository, then any codespaces linked to the fork are deleted, even if you originally created them from the upstream repository.
- If you make a commit from the command line and refuse the new fork by entering
n
, you should push your changes from the command line rather than from VS Code's Source Control view. If you use the Source Control view, VS Code will still try to create a fork for you on push.
When GitHub Codespaces creates a fork, or links your codespace to an existing fork, the following things happen.
- The access token associated with your codespace is updated to include
read
and
write
permission to your fork, in addition to
read
permission to the upstream repository.
- In your Git settings, the upstream repository is reassigned to the name
upstream
, and the fork is added as a new remote repository under the name
origin
.
By default, source control commands that you access from your editor's user interface, such as the
Sync Changes
button in VS Code, target your fork. If you're working from the command line, you can use
origin
to refer to your fork and
upstream
to refer to the upstream repository. For example, you can fetch changes from the upstream repository to ensure your codespace is up to date with the latest changes to the project.
git fetch upstream
When you have made some changes, you can push them to a feature branch of your fork.
git push origin my-feature-branch
For more information, see "
About forks
."