Logo

dev-resources.site

for different kinds of informations.

Copy changed files to another branch in Git

Published at
12/27/2024
Categories
git
Author
Tetsuya KIKUCHI
Categories
1 categories in total
git
open
Copy changed files to another branch in Git
git checkout <branch> -- path/to/file

By the above command, you can pickup files to copy to another branch.

For example,

  1. You've been coding on branch-A for a long time.
  2. You wanna open a PR from some files of them.
  3. Then, execute:
# Switch back to main
git checkout main 
# Create and switch
git checkout -b branch-B 
# Import subset files to branch-B
git checkout branch-A -- path/to/file 

Featured ones: