//home | my other blog | github | twitter | about

Git hints, tips, and tricks

Checking out files from different branches

The git checkout command is not only useful for switching branches or resetting the changes made to a file. It can also be used to checkout a file from a different branch into the current working tree.

$ git status
On branch master

$ git checkout my-feature-branch -- cluster-name.tf

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   cluster-name.tf

This pulled cluster-name.tf from my-feature-branch into the working tree.