In this video, you drew the store’s history as commits and watched what the branch names do when you commit and switch. Here are the key points:
-
A branch is a name that points to one commit. Creating
vitewithgit switch -c vitedidn’t copy any files. It put a second name on the commit that planned the move, wheremainalready pointed. -
The name you’re on moves forward with each commit. Your two commits on
vite, one that addedpackage.jsonand one that added the dayjs entry and the lockfile, each movedviteone commit further.mainstayed on the commit that planned the move, which is how it keeps the working site. -
Switching changes which name you’re on, and your files follow.
git branchmarks the branch you’re on with an asterisk. Aftergit switch main,package.jsonandpackage-lock.jsonare gone from the folder, because the commitmainpoints to doesn’t have them.node_modules/stays, because Git ignores it and never tracked it.git switch vitebrings both files back. -
Git doesn’t record where a branch started.
viteis a name on the dayjs commit, and that commit points back through its parents.mainis a branch like any other, the first name your repository had. -
Deleting a branch deletes the name, not the commits. When you deleted
practicewithgit branch -d practice, the commit it pointed to stayed where it was.
These are the commands from the video, with the folder listing on each branch:
$ git branch
main
* vite
$ ls -C
README.md deals.html index.html package-lock.json pickup.html src
css departments.html node_modules package.json scripts
$ git switch main
Switched to branch 'main'
$ ls -C
README.md deals.html index.html pickup.html src
css departments.html node_modules scripts
$ git switch vite
Switched to branch 'vite'
With that picture in mind, you’re ready for the badge’s code on vite. In the next lesson, you’ll add it, and the home page will stop working in the browser, which is the problem Vite’s dev server solves.