Copy a file from another branch

Git, Branch · Apr 13, 2021

Copies a file from another branch to the current branch.

  • Use git checkout <branch> <file> to copy the specified <file> from the specified <branch>.
git checkout <branch> <file>
git checkout patch-2
git checkout patch-1 "30seconds.txt"
# `patch-2` branch now contains the 30seconds.txt file from `patch-1`

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub.

More like this