# Teaching guide — Session 3

## GitHub, Codespaces and context for an existing project

Take the S2 code to a repository, document it, review a small improvement and understand **commit, push and pull**. Do not rebuild the app. GitHub keeps code and history; Apps Script still runs and deploys the app.

## Format and requirements

Allow roughly 2.5 hours of self-paced work. For groups, adapt the duration; S2 presentations are optional and outside the minimum path. Recommend a computer with a browser, an authorised GitHub account, email and Apps Script access, and an S1/S2 app using fictional data.

## Teacher preparation

- Prepare a **private** practice repository with a README. Work individually on `main`; S4 introduces branches and pull requests. Do not transfer this habit to a shared company repository.
- Check Codespaces and billing using the learner’s account. Compute and storage have quotas; organisation policies may apply. Do not promise unlimited free use or ask learners to enable additional spending.
- Check available AI: access, extension, file permissions and limits. Codespaces does not guarantee Copilot or agent access. Prepare an external chat with attached context and code as an alternative.
- Prepare existing code without secrets or personal data. Leave a placeholder for the spreadsheet ID; keep the real configuration in Apps Script.
- Prepare `context/que-ha-de-fer.md` and `context/arquitectura.md` with project limits and specific tests. The interactive HTML generates them.
- Rehearse diff review, Stage Changes, commit, push and checking github.com. Closing the editor does not push.

## Suggested path: 150 minutes

| Block | Minutes | Result |
|---|---:|---|
| Account and private repository | 20 | README and repository identified |
| Codespaces and AI access | 20 | Editor open, alternative ready if needed |
| Local/remote and versions | 15 | Distinguish save, commit and push |
| Break | 10 | |
| Import code and write context | 30 | Existing code and two documents |
| Improvement, diff and commit/push | 30 | Small reviewed change visible on GitHub |
| Apps Script test and close | 25 | Results recorded and Codespace stopped |

## Concepts to make clear

- **Working copy / local:** files in the Codespace. The machine is in the cloud; “local” describes Git’s relationship with its remote.
- **GitHub / remote:** repository receiving commits through push. A Codespace commit is not on GitHub yet.
- **Save:** update a working file. **Stage:** select content for a commit. **Commit:** record it in local history. **Push:** send commits. **Pull:** incorporate remote changes; conflicts may occur.
- **Sync Changes:** can combine incoming and outgoing changes; it is not simply another name for push. Read and ask for help if rejected or conflicted; do not force push.
- **Codespaces and github.dev:** the first has a remote machine and terminal; the second is a lightweight editor. Neither replaces Apps Script for running `google.script.run`.
- **Agent and external chat:** an agent can edit when connected and authorised. An external chat needs attached files and manually applied results. Review changes and tests in both cases.

## Context activity

1. Copy the working S2 code. Do not duplicate functions if the backend file had another name.
2. Generate and review both documents in the HTML. Explicitly select the portfolio project; do not mix projects.
3. In **what it should do**, specify users, existing features, exclusions, one small improvement and tests with expected results.
4. In **architecture**, keep dining room/frontend, kitchen/backend, pantry/database and storeroom/storage. Open Sheets with `SpreadsheetApp.openById(ID_DEL_FULL)`, using explicit tab and headers, without depending on an active spreadsheet in a web app.
5. Ask AI to summarise what it read first. Attach files if it cannot see them. Context helps but does not guarantee correctness.
6. Review the plan and one small change. Compare the diff, data and preserved features. Do not accept installations or commands you do not understand.

Before the first AI change, save existing code and context, stage, commit, push and check GitHub. This establishes a baseline so the next diff can show only the improvement.

## Commit, push and verification

Review the diff and included data before staging. Create a commit describing the change, push and check the files and commit on github.com. Terminal commands are not required to complete the session.

Test in an Apps Script copy with fictional data and the correct ID at `/dev`. A local test or HTML opened in Codespaces does not establish a real Google test. Without access, record it as pending, not passed.

When it works, move the change to the intended project and update the existing deployment with **New version**. Check the same `/exec`, reading, valid and invalid input, a previous feature and access. A private repository and private app are separate settings.

## Closing and recovery

Save, commit, push and verify github.com. In [Your codespaces](https://github.com/codespaces), select **Stop codespace**. Closing the tab does not stop compute immediately. A stopped environment preserves files and still uses storage; do not delete it before keeping all work you need.

If Codespaces is unavailable, document the project and make commits through GitHub’s website with an external chat. Mark Codespaces as pending: this alternative does not test its environment or terminal. If S2 is unfinished, recover the S1 example with fictional data before requesting an improvement.

Use the [test worksheet](../../fitxa-proves-s2-s3.en.html). The minimum is to explain the change, find it in history and distinguish tested work from pending checks.

## Technical sources

- [Codespaces and github.dev](https://docs.github.com/en/codespaces/the-githubdev-web-based-editor).
- [Included Codespaces usage](https://docs.github.com/en/codespaces/troubleshooting/troubleshooting-included-usage).
- [Copilot in Codespaces](https://docs.github.com/en/codespaces/reference/using-github-copilot-in-github-codespaces).
- [Codespaces lifecycle and stopping](https://docs.github.com/en/codespaces/about-codespaces/understanding-the-codespace-lifecycle).
- [Testing and deploying web apps](https://developers.google.com/apps-script/guides/web).

Content reviewed: 25 October 2026. Check limits and changed screens in the relevant service.
