MODULE 3.2 / 6 OF 8

Git and GitHub without losing work

Save a version, inspect differences and recover a training change.

0% 0 of 0
01 / OSWORKGit is the project's history02 / OSWORKObserve before staging03 / OSWORKSave a version with intent04 / OSWORKClone and update carefully05 / OSWORKRecover without deletinghistory06 / OSWORKPublish only what you reviewed
The six pieces of this module. At the end, you produce a learning evidence.
6 topics
~45 min reading and practice
1 verifiable delivery
Guided training lab

1Git is the project's history

What it is

Git records file versions. A repository is the folder tracked by this history; a commit is a record with changes and a message. GitHub is a service that hosts remote repositories. You can use Git locally without publishing anything on the internet.

Why learn

When an agent changes many files, the history allows you to understand what changed and recover a known version. Git does not replace a full backup: ignored files, databases, and external data need their own protection.

Key concepts

Repository; commit; history; remote; backup.

In practice

A manager changes the report template and loses a section. A previous commit preserves the old content; a clear message helps locate the change.

✓ Do it

Run git --version. In the training folder, use git init -b main. Do not initialize the history in your entire personal folder.

✗ Avoid

Accepting a conclusion without checking the input that supports it.

2Observe before staging

What it is

git status shows new, modified, and staged files. git diff shows changes not yet staged; git diff --cached shows what will go into the next commit. The staging area, called staging, lets you choose exactly which files belong to the same change.

Why learn

git add . stages everything that is not ignored. For learning, prefer naming files: you see the scope better and reduce the risk of including unrelated material.

Key concepts

Working tree; staging; diff; content review.

In practice

You changed README.md and created a private note. git add README.md stages only the documentation. Before committing, git diff --cached confirms what will be recorded.

3Save a version with intent

What it is

Configure user.name and user.email locally to identify authorship. Stage the desired files and use git commit -m with a concrete description. A commit should represent a change you can explain and verify.

Why learn

Messages like “update” make the history less useful. A version is only a reliable point if you know whether it worked and what checks were performed.

Key concepts

Authorship; message; cohesive change; verification.

In practice

“Add instructions to check sales” describes what changed. Then, git log --oneline shows a compact list of the records and their identifiers.

Sequence to try

  1. Prepare a training copy.
  2. Set git config user.name "Your Name" and git config user.email "your-email" in the training. Prepare README.md and .gitignore and create the first commit.
  3. Record the observed result and the next correction.

4Clone and update carefully

What it is

git clone copies a remote repository and its history. git pull fetches and integrates changes into the current branch. Before updating, check git status. In an initial flow, git pull --ff-only only accepts a direct fast‑forward update and stops when histories have diverged.

Why learn

Updating a folder with local changes can cause conflicts. The --ff-only lock is useful information: do not bypass it by discarding work. Inspect the history or ask for help with the context.

Key concepts

Clone creates the folder; pull updates; branch is a line of work; divergence requires review.

In practice

You cloned a project yesterday and today there are new instructions on GitHub. With no local changes, --ff-only usually advances the version. With different commits on both sides, stop and inspect.

✓ Do it

Clone the public repository of this course into a separate folder. Read before running any received program, including from known repositories.

✗ Avoid

Mix the training copy with private files or production work.

5Recover without deleting history

What it is

git revert creates a new commit that undoes a previous change. It is appropriate for fixing a record that has already been shared. git restore discards unsaved changes of selected files; it can lose work. Do not teach reset --hard as an automatic response to any difficulty.

Why learn

Recovery tools have different consequences. Identify whether the change is only in the file, in a local commit, or published before choosing the command.

Key concepts

Revert preserves history; restore discards selected changes; recovery requires diagnosis.

In practice

In the training, make a second commit changing the README title. git revert HEAD creates a third commit that restores the previous title, without hiding that the change occurred.

6Publish only what you reviewed

What it is

git push sends commits to the remote. Before that, check the account, the destination URL, the scope of the files and the absence of credentials. A public repository remains accessible to third parties; a private one also requires access control. Publishing a site is an additional step, depending on the hosting.

Why learn

Mixing save and publish leads to accidental exposure. Separate “record locally”, “push to GitHub” and “put the site live” in your checklist.

Key concepts

origin; push; visibility; credentials; publication.

In practice

A local README may contain drafts. The commit preserves those drafts on the machine. Only push when you have decided they can be part of the chosen remote.

Criteria to review your delivery

Use this rubric after the lab. Each line asks for evidence; checking reading does not mean the practice was performed.

Criterion Expected evidence If not passed
Scope The delivery matches the objective of this class. Reduce the task and name a single result.
Inputs You know which files or data were used. List the sources and remove unrelated material.
Execution The procedure was carried out in the training environment. Differentiate what was planned from what was done.
Verification A result was compared with a reference. Open the file or repeat the verifiable query.
Secrets No token, password, or private data was shared. Review the work copy before any submission.
Continuity Another person can find the next step. Update README and record a concrete pending item.

GET HANDS-ON / ~15 MIN OR IN STEPS

Your first recovery point

Use fictional files and a training folder. Practices involving installation, Telegram or VPS may require additional time for registration and configuration.

Git · only in the training folder

Read the block before using. Fields like Your Name and usuario@ip-da-vps are examples to adapt; administrative commands belong only to your training environment.

git init -b main
git config user.name "Seu Nome"
git config user.email "seu-email"
git status
git add README.md .gitignore
git diff --cached
git commit -m "Registra estrutura inicial de treino"
git log --oneline

Ready criterion

Save a version, inspect differences and recover a training change. Record the produced file, the test run and the observed result.

Open lab files and models

Check what remained

git commit already sends the files to GitHub?

View commented answer

No. Commit records locally; push sends to the configured remote.

If your answer was different, return to the corresponding topic and write the difference in one sentence. The check does not block your study.

Module summary

  • Repository; commit; history; remote; backup.
  • Working tree; staging; diff; content review.
  • Authorship; message; cohesive change; verification.
  • Clone creates the folder; pull updates; branch is a line of work; divergence requires review.
  • Revert preserves history; restore discards selected changes; recovery requires diagnosis.
  • origin; push; visibility; credentials; publication.

Consult the source

Tools verified on 20/09/2026; screen names and availability may change.

Full module