This activity is designed to prepare you for future Python labs where you will begin each exercise with a starter repository on GitHub. In those labs, you will open the repository in GitHub Codespaces, edit Python files, and run your code directly inside the Codespaces environment. You will also need to push your changes back to GitHub so your work is saved and visible to your instructor, and in some cases, you may need to pull updates from GitHub if new code or instructions are added after you start. By practicing these steps now, you will be able to focus on Python coding in future labs without worrying about learning Git and Codespaces workflow at the same time.
Goal:
- Open a repository in GitHub Codespaces
- Edit a Python file in the Codespaces editor
- Use the terminal for all Git commands (
status
,add
,commit
,push
,pull
) - Make a change on GitHub (web) and pull it back into Codespaces
- On GitHub, open the repository your instructor provided.
- Click Code → Codespaces → Create codespace on
main
. - Wait for the Codespace to finish loading.
- In the menu, click Terminal → New Terminal (you will run all Git commands here).
In the terminal run the following commands one after the other.
python --version # or: python3 --version
python hello_world.py # or: python3 hello_world.py
Expected output:
Hello, World!
- In the Explorer panel, click on
hello_world.py
. - Change the line:
to:
print("Hello, World!")
print("Hello — I'm <Your Name> (Codespaces edit)")
- Save the file (Ctrl+S or Cmd+S).
Run the following command to see what changes Git has detected in your project:
git status
This command shows the current state of your working directory and staging area. After you edited hello_world.py in the Codespaces editor, that change exists only in your local Codespaces environment (a virtual machine running in the cloud). At this stage, Git knows the file has been modified, but the change has not yet been staged or committed. You should see hello_world.py listed as modified, which means Git has detected differences between your current file and the last saved version in the repository history.
Now run the following command to stage the modified file so Git knows you want to include it in the next commit:
git add hello_world.py
Staging tells Git that this file should be part of the next snapshot of the project history. Right now, the change still exists only in your local Codespaces environment, but staging it is the first step toward saving it in the repository history.
Check again:
git status
Next, run the following command to commit your staged change:
git commit -m "Update greeting to <Your Name>"
A commit records your staged changes in the local Git history inside your Codespaces environment. This creates a permanent checkpoint in the project, with your custom message describing what you changed. At this stage, the commit still exists only locally — it is not yet on GitHub.
Check recent commits:
git log -n 3 --oneline
Now, run the following command to send your local commit to the GitHub repository:
git push
Explanation: Pushing uploads your local commits from the Codespaces environment to GitHub’s remote repository. This makes your changes available online, so you (and your instructor) can see them from GitHub’s website.
In your web browser, go to your repository on GitHub, open the hello_world.py file, click Edit, make a small change (e.g., modify the message again), and then click Commit changes. This simulates a situation where changes are made directly on GitHub — perhaps by you from another device or by your instructor. These changes now exist only in the remote GitHub repository, not in your Codespaces environment.
- In your browser, open
hello_world.py
in the GitHub repo. - Click the pencil icon to edit.
- Change the print message again.
- Commit directly to
main
.
Finally, run the following command in Codespaces to download the latest changes from GitHub:
git pull origin main
Pulling updates your local Codespaces environment with changes from the remote GitHub repository. This ensures you are working with the latest version of the project before you continue coding.
Run the program again to confirm:
python hello_world.py
git status
→ See which files are changed/staged/untracked.git add <file>
→ Stage changes for commit.git commit -m "message"
→ Save staged changes locally.git push
→ Send local commits to GitHub.git pull origin main
→ Fetch and merge changes from GitHub.