git checkout
An older all-purpose command that switches branches and also restores files; newer Git splits these jobs into git switch and git restore.
In more detail
git checkout -b feature/42-new-button creates a branch and switches to it, like git switch -c. During a merge conflict, git checkout --ours or --theirs takes one side of a file entirely. It still works everywhere, so you will meet it in older instructions.
Example
git checkout -b feature/42-new-buttonRelated terms
- git switch — The command that moves you to another branch, updating HEAD and the working tree to match; -c creates the branch first.
- git restore — The command that throws away uncommitted changes to a file, or with --staged takes a file back out of the staging area.
- ours and theirs — During a merge, ours is the branch you are on and theirs is the branch being merged in.
Taught in
- Why Version Control, And Why Git Won — Advanced Git Internals & Distributed Workflows
- Reading History: log, show And diff — Advanced Git Internals & Distributed Workflows
- A Branch Is A Moving Pointer — Advanced Git Internals & Distributed Workflows
- What A Remote Actually Is — Advanced Git Internals & Distributed Workflows
- The Pull Request, And Branch Naming — Advanced Git Internals & Distributed Workflows
- Resolving A Conflict, Line By Line — Advanced Git Internals & Distributed Workflows
- Cherry Picking, Reflog, And Getting Work Back — Advanced Git Internals & Distributed Workflows
- Investigating History: blame, bisect And worktree — Advanced Git Internals & Distributed Workflows
- Tags And Releases — Advanced Git Internals & Distributed Workflows