git switch moves HEAD to another branch, and puts that branch's files in your folder. The branch HEAD points at is your current branch: new commits move it, and no other.
git switch feature/faq
Switched to branch 'feature/faq'
git add faq.html
git commit -m "Add the FAQ"
[feature/faq 3bfe6c1] Add the FAQ
1 file changed, 1 insertion(+)
create mode 100644 faq.html
git log --oneline --all
3bfe6c1 (HEAD -> feature/faq) Add the FAQ ← only feature/faq moved
8cf7637 (main) Add prices
27abc14 Start the shopBack on main, the FAQ isn't in the folder: it's only on feature/faq.
git switch main
Switched to branch 'main'
ls
app.js README.md-c makes a branch at the commit you're on and switches to it, in one step:
git switch -c fix/footer
Switched to a new branch 'fix/footer'Older guides use git checkout for both. It does the same: git checkout <branch> switches, and git checkout -b <name> makes and switches.
Objectives
- Switch to the cart branch.
- Commit the cart on that branch only.
- Start a fix branch from
main, and switch to it.