David Xia
David Xia

Reputation: 5453

How to copy a file from one git branch to another and save as different file?

I'd like to copy a file from one git branch to another but save it as a different filename. I know I can do this to copy it over with the same name. Is there a way to rename during the checkout?

git checkout otherbranch myfile.txt

Upvotes: 4

Views: 291

Answers (2)

Bhavesh Ajani
Bhavesh Ajani

Reputation: 1261

let's understand with an example: if you want to copy the index.html file from the master branch to develop branch with different file name then

step-1: checkout to develop branch

git checkout develop

step-2: copy file from master to develop branch

git show main:index.html > new_index.html

step-3: add this new file

git add .

step-4: commit file

git commit -m "message"

step-5: and push file

git push

Upvotes: 1

the.malkolm
the.malkolm

Reputation: 2421

git show otherbranch:myfile.txt > myfile2.txt

Upvotes: 9

Related Questions