DEV Community

Tetsuya KIKUCHI
Tetsuya KIKUCHI

Posted on

Copy changed files to another branch in Git

git checkout <branch> -- path/to/file
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more