I have folder name utils
I want to copy
this folder from master
branch to work
branch. How do I do that ?
1 Answer
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.
-
4Just for consideration, when
work
andmaster
get merged again there will be a conflict because of the different operations that happened on each side. Aug 2, 2013 at 19:43 -
Interestingly I tried this. And when I merged my branch back to
master
, I had no conflict. Maybe git has gotten smarter?– clinuxMay 23, 2016 at 23:30 -
I had an issue but I fixed it adding origin: git checkout origin/master -- PUBLISH Mar 31, 2020 at 16:51
-
@Carl Norum does the
copy
example also applies to changing the ALREADY EXISTING IN WORK BRANCHutils
folder onto themaster
version?– aerijmanJan 28, 2021 at 18:43 -
I'm not sure I follow - if you want to get changes from your work branch back onto maaster, just rebase or merge. Jan 28, 2021 at 20:30
master
anymore, but you do want it onwork
? Or you just want to copy it over towork
?git subtree push
to do this with one command. See gist.github.com/cobyism/4730490 for example.