#Git – How restore a file from another branch

-Having a main branch called “main” and a working branch called “myproject” we want to restore on branch “myproject” the file “filename.ext” with the version on branch “main

-We switch to the “myproject” branch

git checkout myproject

-We use the restore command

git restore –source mainfilename.ext

-Now we must stage and commit the change of the file “filename.ext” on branch “myproject

Tested on: Git 2.36

Leave a comment