Git: Copy File From Another Branch
Created on April 17, 2026
commandline, git
Sometimes you are on a branch a and need a file from branch b. Here is how to do it.
One way to do it is using git checkout branch with a -- path/to/file at the end.
git checkout main -- webserver/pyproject.toml
However, this will stage the file, and in many cases, you do not want to stage it.
Therefore, an alternative is using git restore:
git restore --source=main -- webserver/pyproject.toml