Quckie: git - copy a file from another branch without switching branch

Tag
Author: Ally
Published:

Summary:

Copy a file from another git branch without checking to that target branch.

Ever wanted to grab a file from another branch in git, but don’t want to checkout to the target branch?

git-show to the rescue.

export BRANCH="123-feature"
export INPUT="app/Http/Livewire/MyComponent.php"
export OUTPUT="MyComponent-123-feature.php"
git show $BRANCH:$FILE > $OUTPUT

Or git-diff if you to do that:

git diff master:app/Http/Livewire/MyComponent.php \
  feature:app/Http/Livewire/MyComponent.php
Git image
Building an image for static site generator output
Laravel post migration event listener
To bottom
To top