Explore Git History
Reading history, understanding commits over time, and using history as a learning tool.
Challenge Coach audio
Challenge Coach Transcript
Alex and Jamie walk through this challenge step by step.
Alex: Welcome back. Today we're doing Bonus E, Git History, and the goal is to read a repository's past instead of only looking at its current files.
Jamie: I like that framing, because history can feel like a wall of mysterious messages. This challenge makes it visual, right?
Alex: Exactly. You'll explore the learning-room repository, which is the per-learner repo where your Day 1 issue, branch, commit, pull request, and merge work happened. The challenge asks you to use GitHub Desktop, or GitHub.com if you prefer, to see commits, branches, and merges over time.
Jamie: And this is one of the bonus challenges that unlocks after Challenge 15, yes?
Alex: Yes. After Challenge 15 unlocks the next path, Bonus Challenges A through E become available as a structured set. You can choose this one without waiting for Challenge 16, and Challenge 16 itself is the Capstone Project.
Jamie: Before we open a history view, I want the Git model in my head. What am I actually looking at when I see all those commits?
Alex: You're looking at saved snapshots. When you work locally, Git separates your project into the working directory, the staging area, and the repository. The working directory is the folder you edit, the staging area is where you choose what will go into the next commit, and the repository is the saved record in the hidden .git folder.
Jamie: So a commit is not just a note that says something changed. It is a saved point in the project.
Alex: Right. A commit records the snapshot, a message, the author, and a pointer to the commit that came before it. It also gets a unique ID called a SHA hash, usually shown as a short seven-character version like a1b2c3d. You do not need to memorize hashes, but they are useful when you want to identify one exact moment.
Jamie: Where do branches fit into that?
Alex: A branch is a movable name that points to a commit. The default branch is often main, and your learning branch may be named something like learn/YOUR-USERNAME. HEAD is Git's way of saying which branch or commit you are currently on.
Jamie: And local versus remote is the two-copy part: one copy on my computer, one copy on GitHub.
Alex: Yes. Push sends your local commits to GitHub. Pull brings remote updates down and merges them into your current branch. Fetch checks what changed on the remote without merging, which is useful when you just want to update what your tools know before reading history.
Jamie: Now the timeline view makes more sense. It is not just decoration. It is showing how snapshots connect.
Alex: That's the core of this challenge. A straight line of commits shows one path through time. A branch creates another path, and a merge brings paths back together. In a visual graph, those paths may appear as parallel lines that split and reconnect.
Jamie: The challenge asks some very specific observation questions, too.
Alex: It does. You're asked to find how many branches exist right now, locate your Challenge 5 commit, see where your learn/YOUR-USERNAME branch diverges from main, find the merge commit from your Challenge 9 pull request, and identify the oldest commit in the repository.
Jamie: That oldest commit is often the one that created the starting project structure, sometimes called the initial commit.
Alex: Exactly. And the merge commit is interesting because it usually has two parent commits. That means it connects two lines of work: the main line and the branch that was merged.
Jamie: Let's start with GitHub Desktop, because the challenge is really built around that visual timeline.
Alex: Open GitHub Desktop and choose the learning-room repository. If it is not already visible, use the repository picker to find it. Then open the History tab, where the left side lists commits and the right side shows details for the commit you selected.
Jamie: What should I listen for or look for once I'm in that tab?
Alex: Move through the commits and pay attention to the message, author, date, and changed files. Click or select a commit to inspect the diff, which is the set of lines added, removed, or modified. Some commits will be yours, and some may be seeded peer-simulation commits that make the repository history more realistic.
Jamie: What if GitHub Desktop does not show all the branches I expect?
Alex: Fetch from the remote first. In GitHub Desktop, use Repository, then Fetch origin. That updates Desktop's knowledge of remote branches without forcing you to merge anything into your current work.
Jamie: So after fetching, I can compare what I remember doing with what the timeline actually records.
Alex: Yes. Look for your Challenge 5 commit message, then look for the branch line that contains it. Then look for where that branch separates from main and where your Challenge 9 pull request came back in as a merge.
Jamie: If someone does not want to use Desktop, GitHub.com gives them another path.
Alex: It does. In the learning-room repository on GitHub.com, the Code tab usually has a commits link near the top showing the number of commits. Open that to see the linear commit history, with the most recent commits first.
Jamie: That page includes the author, date, message, and SHA for each commit, right?
Alex: Yes. Select a commit and GitHub shows the diff. Visually, added lines are commonly shown in green and removed lines in red, and the text diff still carries the actual line changes for assistive technology to read.
Jamie: And the branch graph is under Insights, then Network.
Alex: Correct. The Network graph can show branches as lines that diverge and merge, but it can be busy in repositories with several contributors or simulation commits. If it is hard to read, narrow your attention to a date range, search commit history for your username, or use the branch filter where available.
Jamie: So GitHub.com gives me both a simple list and a more graph-like view.
Alex: That's a good way to say it. The commits page is easier for reading one commit at a time. The Network graph is better for seeing how branches relate.
Jamie: Where does VS Code fit into this challenge? It is mentioned as another history tool, but not quite the same as Desktop.
Alex: VS Code's Timeline view is file-focused. In the Explorer sidebar, you can open Timeline for the current file, and it shows commits that changed that file. That is excellent when you want to know how one document evolved.
Jamie: So if I open a README, the Timeline view is not necessarily showing the whole repository's story.
Alex: Right. It is a narrower lens. For the bonus evidence, GitHub Desktop or GitHub.com is better for branches and merges, while VS Code Timeline is great for answering, who changed this file, when, and why.
Jamie: That also helps when a file suddenly looks unfamiliar. I can inspect its history instead of assuming I broke something.
Alex: Exactly. And if you use VS Code Source Control, files are grouped so you can tell what is changed, what is staged, and what is ready to commit. Running git status in the terminal gives the same kind of orientation in text.
Jamie: This bonus also connects to the advanced Git appendix, because a lot of advanced commands start with reading history carefully.
Alex: They do. Cherry-pick, for example, begins by finding the SHA for one specific commit, then applying that commit to your current branch. You might find the SHA in VS Code Timeline, with git log branch-name --oneline, or through a GitHub API query with gh, then run git cherry-pick a1b2c3d.
Jamie: And if cherry-pick runs into a conflict, it pauses like a merge conflict.
Alex: Yes. You resolve the marked files, stage them, and run git cherry-pick --continue. If you decide this was the wrong move, git cherry-pick --abort returns you to where you started.
Jamie: Interactive rebase is another history tool, but it sounds more powerful and more dangerous.
Alex: It rewrites commits, so use it with care. With git rebase -i HEAD~3, you can edit the last three commits: keep them, squash them together, reword messages, drop one, or pause to amend one. It is best for commits that have not been pushed to a shared branch.
Jamie: That explains why history is not just something you read after the fact. Sometimes you clean it up before asking people to review your pull request.
Alex: Exactly. A tidy history can make review easier, but safety comes first. If you get into trouble during a rebase, git rebase --abort is the escape hatch, and git status will usually tell you what Git is waiting for.
Jamie: Undo commands are where I always want extra caution. Reset and revert sound similar, but they are not the same.
Alex: Good instinct. git reset moves where your branch points and can keep changes staged, keep them unstaged, or discard them depending on the mode. git revert is safer for shared branches because it creates a new commit that undoes an older commit, leaving the existing history intact.
Jamie: Tags are history markers too, right? Like naming an important release point.
Alex: Yes. A lightweight tag is a simple name for a commit, and an annotated tag includes extra metadata and is commonly recommended for releases. You can create tags in Git, push them to GitHub, list them, show details, or delete local and remote tags when needed.
Jamie: What about detached HEAD? That phrase sounds worse than it is.
Alex: It means you are looking directly at a commit instead of being on a branch. If you only meant to inspect history, switch back to your branch. If you made commits there and want to keep them, create a new branch at that point so the work has a name.
Jamie: And force pushing is the one where the appendix says to prefer --force-with-lease over plain --force.
Alex: Right. --force-with-lease checks whether someone else pushed since your last fetch, and it fails instead of overwriting their work. A common flow is rebase your feature branch onto main, resolve conflicts, continue the rebase, then push with --force-with-lease because the remote branch still has the old commit shape.
Jamie: Branch protection can block that kind of direct push or merge too.
Alex: Yes. Protected branches may require pull requests, reviews, passing checks, or up-to-date branches. The reliable flow is to work on a branch, commit, push that branch, open a pull request, wait for review and checks, and merge through the pull request when the rules are satisfied.
Jamie: Two more advanced tools are very history-centered: bisect and clean.
Alex: git bisect helps find the commit that introduced a bug. You mark the current commit as bad, mark an older known-good commit, and Git checks points in between until it narrows down the first bad commit. You can do it manually or have Git run a test script at each step, then finish with git bisect reset.
Jamie: git clean is less about commit history and more about clearing untracked files, but it can affect your working folder fast.
Alex: Exactly, so dry-run first. git clean -n shows what would be removed, while -f actually removes files, -d includes directories, -x includes ignored files, and -i lets you confirm interactively. If you are unsure, do not jump straight to deletion.
Jamie: The appendix also mentions using GitHub Copilot for Git operations, not as a substitute for understanding, but as help with confusing output.
Alex: Yes. You can paste git status, git log, git show, a conflict message, or a branch protection error into Copilot Chat and ask what it means. Copilot can also help draft clearer commit messages or suggest which Git command matches the result you want, but you still verify before running anything that rewrites or deletes work.
Jamie: If a learner gets stuck during this bonus, what are the simple recovery moves?
Alex: If Desktop looks incomplete, fetch origin. If the Network graph is overwhelming, use the commits list instead or focus on a smaller time period. If you cannot find your own work, search for your username, your branch name, or a commit message you remember.
Jamie: And the evidence box is not asking for a perfect diagram. It is asking what they discovered.
Alex: Right. Include the tool you used, the number of branches you found, your Challenge 5 commit, where your learning branch diverged from main if you could identify it, the Challenge 9 merge commit if you found it, the oldest commit, and one surprising thing you noticed. If you explored at least one commit diff and can explain what the history tells you about the project, you have done the work of this bonus.
Jamie: I like that because it turns Git history into a study tool. You can learn from the path the project took, not only from the final file state.
Alex: Exactly. Git history is a navigable record of change: who changed what, when it changed, and how separate lines of work came back together. Once you can read that record, advanced Git becomes much less mysterious.
Reference Solution
Solution Reference: Bonus E -- Explore Git History Visually
This shows a visual history exploration.
On github.com
Viewing commit history
- Navigate to any repository
- Click the "X commits" link near the top (shows total commit count)
- The history page shows each commit with author, date, message, and SHA
- Click any commit to see what changed (green lines added, red lines removed)
What you see
The commit history tells the story of a project:
- Chronological order: Most recent commits first
- Author attribution: Every change has a name attached
- Commit messages: Each entry explains what changed and (ideally) why
- Diffs: Click any commit to see exactly which lines were added, removed, or modified
In GitHub Desktop
Visual timeline
- Open the repository in GitHub Desktop
- Click the "History" tab
- The left panel shows commits as a timeline
- Click any commit to see the diff in the right panel
- The branch visualization shows where branches diverged and merged
Key observations from exploring history
- Merge commits show where two branches came together -- they have two parent commits
- The first commit in a repository is often called "initial commit" and creates the project structure
- Commit frequency varies -- some days have many commits, others have none. This is normal.
In VS Code
The "Timeline" view in the Explorer sidebar shows the history for the currently open file. Each entry is a commit that changed that file. This is useful for understanding how a specific file evolved.
What matters
The learning objective is understanding that Git history is a navigable record of every change. If you explored the commit history, clicked into at least one commit to see its diff, and can describe what the history tells you about the project, you completed this bonus.
Authoritative Sources
Use these official references when you need the current source of truth for facts in this chapter.
Section-Level Source Map
Use this map to verify facts for each major section in this file.
- On github.com: GitHub Docs, home, GitHub Changelog, About Git, GitHub flow, About pull requests
- In GitHub Desktop: GitHub Docs, home, GitHub Changelog, About Git, GitHub flow, About pull requests
- In VS Code: GitHub Docs, home, GitHub Changelog
- What matters: GitHub Docs, home, GitHub Changelog