To checkout a file from another branch, run the following command:
git checkout <branch-name> -- <path/to/file>
# suppose you are in dev branch, to checkout file from main branch:
git checkout main -- src/app.js
For git >= 2.23, run the following command:
git restore --source <branch-name> -- <path/to/file>
# suppose you are in dev branch, to checkout file from main branch:
git restore --source main -- src/app.js
References #
https://stackoverflow.com/questions/2364147/how-to-get-just-one-file-from-another-branch
Tags
git🙏🙏🙏
Since you've made it this far, sharing this article on your favorite social media network would be highly appreciated 💖!
Published