How to checkout a file from one git branch to another?
Hello and welcome back to my blog! Today I wanted to write about something new that I learned I can do with the git checkout command.
Consider this, you have a bunch of files that you are working with in your current developmment branch. Now you need to start a new feature, but you need only a subset of files from your current development branch that needs to be ported to the new one.
Here is how you go about this:
Scenario:
Let's call your git repository as TheNetworkHippoRepo
. Say you have a branch called branch-a
in this repository where you have a file called file-a
. Let's assume there are a bunch of other files too, but file-a is the one of interest to us.
Now you need to develop a new feature, and you create a new branch off of your mainline called branch-b
. Here's how you can "checkout" file-a from branch-a to branch-b:
git checkout branch-a -- file-a
And just like that, you have only file-a available in your new branch!
Hope you learned something new!
#thenetworkhippo