Git Copy a folder from master branch to another branch

GitGithub

Git Problem Overview


I have folder name utils I want to copy this folder from master branch to work branch. How do I do that ?

Git Solutions


Solution 1 - Git

To copy the folder over:

$ git checkout work
Switched to branch 'work'
$ git checkout master -- utils
$ git add utils
$ git commit -m "Adding 'utils' directory from 'master' branch."
[work 9fcd968] Adding 'utils' directory from 'master' branch.
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 utils/file

If you want to delete it on master after that:

$ git checkout master
Switched to branch 'master'
$ git rm -r utils
rm 'utils/file'
$ git commit -m "Removing 'utils' directory."
[master c786f95] Removing 'utils' directory.
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 utils/file

Then you can just git push as necessary. Git's output in your project may be different; I just made a simple test repo here with only one file in the utils directory.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2579475View Question on Stackoverflow
Solution 1 - GitCarl NorumView Answer on Stackoverflow