Copying a file from another branch in Git

Copying a file from another branch into my current branch is something I do every so often in Git, e.g. when I want to reset a file in staging to match that of master. Fortunately Git makes this easy:

git checkout source_branch source_file.txt

The copied file will automatically be staged, so you don’t need to run git add.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.