iamafasha
iamafasha

Reputation: 794

Is there a way of copying a file from on branch to another but with different name?

“I’m having two branches i.e master and minified, and I want to be able to copy a file from master to minified but get it with a different name.

I have tried git checkout

git checkout master index.html

I want index.html to be copied to minified as maybe

index_from_master.html

Upvotes: 0

Views: 83

Answers (1)

mfnx
mfnx

Reputation: 3018

You could just do this:

git checkout minified
git show master:index.html > index_from_master.html # get content and write to new file

Also, if index.html does not exist on branch minified:

git checkout minified
git checkout master -- index.html # checkout file
git mv index.html index_from_master.html # rename file

If index.html already exists and you don't want to replace it with the version in master, you could first temporarily rename index.html in minified and do the above. Or without the temporarily renaming:

git checkout minified
git checkout master -- index.html # replacing the index.html from minified if any
git mv index.html index_from_master.html
git fetch origin
git checkout origin/minified -- index.html # get file back from working area

Upvotes: 3

Related Questions