In my git development I am using the following checkout command structure to bring in solitary files from other branches into my working directory.
git checkout [<tree-ish>] [--] <pathspec>…
As per documentation, this also updates my index with the file as if I wanted to commit it - leaving me with the extra step of deleting it from my index if I don't want to commit the file. (We're doing development with binary files :( and this way of working is helpful for testing our individual work that may relate to the work of another developer that's working in parallel)
Is there any way to pull/checkout a singular file from a branch/commit such that it updates the working directory and NOT the index?
I figure I could alias the two steps into a single command, but I'm curious if there is already a (single) git command capable of accomplishing this.
git restore --source=<tree> --worktree <pathspec>...
See the manpage.
Another way would be
git show otherBranch:fileName > fileName
This creates a new file with the content of the file in the other branch
Anyway if your workflow requires this step to be done often, I would create an alias
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With