Written By
Views

Copy a file from a git branch to the other

Copy a file from a git branch to the other

Working with GIT is one of the best things that happened to software development. However, sometimes in very rare instances, you may have the need to copy(checkout) a file from one branch to the other.

Here is a quick tip should you ever need to do that, assuming you want to copy the file "composer.lock" from branch A to B

  1. Check into branch A and pull in the latest changes
git checkout A && git pull
  1. Check into branch B
git checkout B
  1. Checkout the file - make sure to use the correct path
git checkout A composer.lock
  1. Should you wish to add the file to the current branch, run this:
git add composer.lock

That's it, hope it was useful 🤩🤩🤩

Comments (0)

loading comments