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.

Posted in Git

Leave a Reply

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