Lesson 06
Checkout
Checkout selects an existing branch to work on: it moves HEAD and updates tracked files to match that branch.
Visual Explanation
Ready to run git checkout feature/login.
Keep These Ideas
- Select, Don't Rebuild
- Checking out an existing branch selects it; the branch and its commits already exist.
- HEAD Moves
- HEAD identifies the branch or commit you currently have checked out.
- Files Follow
- Tracked Working Directory files update to match the selected branch when it is safe.
The Real Command
git checkout feature/loginThis switches to the existing feature/login branch and updates your project files to that branch's version.
Command Details
git switch feature/loginModern, focused branch switching. switch is the clearer modern command when your only goal is to change branches.
git checkout -b feature/search-b creates and checks out a branch. Use a new branch name that does not already exist.
git status --short --branch--branch confirms the current branch. The concise header shows where HEAD is attached.
## feature/logingit checkout -- app.jsThis older form restores app.js. It discards unstaged edits. Modern Git offers git restore app.js for this job.
git checkout a1b2c3dChecking out a commit detaches HEAD. You can inspect an old checkpoint, but new work needs a branch if you want to keep it easily.
Note: switching to 'a1b2c3d'.
You are in 'detached HEAD' state.
HEAD is now at a1b2c3d Add navigationKnowledge Check
Move Between Lines of Work
Select an existing line of work, understand HEAD, and recognize checkout's older multi-purpose forms.
Question 1 of 5
- Question 1: current
- Question 2: not started
- Question 3: not started
- Question 4: not started
- Question 5: not started