Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Copy a folder from master branch to another branch

Tags:

git

github

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

like image 227
user2579475 Avatar asked Aug 01 '13 16:08

user2579475


People also ask

How do I copy files from one directory to another in git?

The easiest way to copy files and folders from within a working tree is to use the right-drag menu. When you right-drag a file or folder from one working tree to another, or even within the same folder, a context menu appears when you release the mouse.


1 Answers

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.

like image 132
Carl Norum Avatar answered Sep 29 '22 19:09

Carl Norum