Gitastic
Path › Part 5: Power tools › Lesson 16 of 16
16

Tags & tidy history

Mark releases forever, and clean up your commits before you share them.

1 Learn the idea

Two finishing touches. Tags give a permanent name to an important commit ("this is version 1.0"). Tidying turns a messy trail of "WIP" and "fix typo" commits into one clear commit before anyone else sees it.

Tags

  • git tag v1.0 pins the name v1.0 on the current commit. It never moves when you commit later.
  • Tags are not pushed automatically: git push origin v1.0 (one tag) or git push --tags (all).

Tidying your own commits

  • git commit --amend replaces the last commit with a new one — fix the message, or add a forgotten file.
  • git reset --soft HEAD~3 moves the branch back 3 commits but keeps all their changes staged. One git commit then makes a single clean commit.
  • In real git, git rebase -i HEAD~3 does the same interactively (squash, reorder, reword) in an editor. This simulator has no editor, so we use the reset trick — same result.

2 Watch it happen

Release, fix a typo, squash the mess

Press Play or use → to step through. Watch the graph as each command runs.

e00120d Initial appe00120dInitial app09e8881 Add login09e8881Add loginHEAD = where you are. It points at the current branch.HEAD →Branch "main" — a movable pointer (current branch: moves when you commit)mainRemote-tracking branch: where origin's main was last time you fetchedorigin/main
terminal · simulated, no real repository is touched
Read this demo as text
  1. $ git tag v1.0

    We ship! v1.0 is pinned to this commit — a tag: v1.0 label in the graph.

  2. $ edit app.js "app v2 with search"
    $ git commit -am "Add serach"

    New work… and a typo in the message. Note how main moved forward, but v1.0 stayed put. That is the difference between branch and tag.

  3. $ git commit --amend -m "Add search"

    --amend replaces the last commit. The old one is not edited — a new commit is made, and the faded one is left behind.

  4. $ edit app.js "app v2 with search + filter (WIP)"
    $ git commit -am "WIP"

    Now a typical real-life trail of small commits…

  5. $ edit app.js "app v2 with search + filter"
    $ git commit -am "fix typo"

    …"fix typo"…

  6. $ edit app.js "app v2 with search + filters, tested"
    $ git commit -am "really works now"

    …"really works now". Nobody wants to read this history later.

  7. $ git reset --soft HEAD~3

    reset --soft HEAD~3 moves main back three commits. The changes are all still staged — nothing is lost.

  8. $ git commit -m "Add search filters"

    One commit with one clear message replaces the three messy ones. The old commits fade out.

  9. $ git tag v1.1
    $ git push
    $ git push --tags

    Tag the new release, push the branch, then push the tags (they are never sent automatically).

  10. $ git log --oneline

    A clean, readable history: every commit tells a story, releases are marked.

Branch
  • Moves forward with every commit
  • Where you work
  • Pushed with git push
Tag
  • Never moves
  • Marks a release or milestone
  • Pushed with git push origin <tag> / --tags
git tag v1.0Pin a permanent name to the current commit
git push origin v1.0 / --tagsPublish one tag / all tags
git commit --amendReplace the last commit (message or content)
git reset --soft HEAD~NUndo N commits, keep changes staged → squash

3 Check your understanding

Question 1

In this graph, you make another commit on main. What happens to the labels?

e00120d Initial appe00120dInitial app09e8881 Add login09e8881Add loginHEAD = where you are. It points at the current branch.HEAD →Branch "main" — a movable pointer (current branch: moves when you commit)mainTag — a pointer that never movestag: v1.0
Question 2

You created tag v2.0 and ran git push. Is the tag on the remote?

Question 3

You have 4 local, unpushed commits ("WIP", "wip 2", "fix", "done"). How do you turn them into one commit in this simulator?

Question 4

You pushed a commit, then ran git commit --amend. What happens on your next git push?

4 Practice for real

Your mission

Clean up and release

Your 3 local commits are a mess. Squash them into a single commit with the message Add profile page (so history is: "Add profile page" → "Initial app"), tag it v2.0, and push both main and the tag to origin.

origin (GitHub — shared with your team)
e00120d Initial appe00120dInitial appBranch "main" — a movable pointer (current branch: moves when you commit)main
your laptop ~/project · on main
e00120d Initial app click to insert the hash into the terminale00120dInitial app180a7e0 WIP click to insert the hash into the terminal180a7e0WIPcedbcac more WIP click to insert the hash into the terminalcedbcacmore WIP7cf990e fix it for real click to insert the hash into the terminal7cf990efix it for realRemote-tracking branch: where origin's main was last time you fetchedorigin/mainHEAD = where you are. It points at the current branch.HEAD →Branch "main" — a movable pointer (current branch: moves when you commit)main
terminal · simulated, no real repository is touched
Type commands below. `help` lists everything. Tab completes, ↑ recalls. Click a commit to paste its hash.
~/project (main) $