Git Copy a folder from master branch to another branch

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)