Skip to content

TR-Seneca-Python/introduction-to-github-codespaces

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Introduction to GitHub Codespaces and Git commands

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:

  1. Open a repository in GitHub Codespaces
  2. Edit a Python file in the Codespaces editor
  3. Use the terminal for all Git commands (status, add, commit, push, pull)
  4. Make a change on GitHub (web) and pull it back into Codespaces

1. Open the repo in Codespaces

  1. On GitHub, open the repository your instructor provided.
  2. Click Code → Codespaces → Create codespace on main.
  3. Wait for the Codespace to finish loading.
  4. In the menu, click Terminal → New Terminal (you will run all Git commands here).

2. Check Python & run the program

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!

3. Edit the file in the Codespaces editor

  1. In the Explorer panel, click on hello_world.py.
  2. Change the line:
    print("Hello, World!")
    to:
    print("Hello — I'm <Your Name> (Codespaces edit)")
  3. Save the file (Ctrl+S or Cmd+S).

4. View changes in Git

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.


5. Stage the change

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

6. Commit the change

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

7. Push the commit to GitHub

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.


8. Make a change on GitHub (web)

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.

  1. In your browser, open hello_world.py in the GitHub repo.
  2. Click the pencil icon to edit.
  3. Change the print message again.
  4. Commit directly to main.

9. Pull the web change into Codespaces

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

10. Git command summary

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published