Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I copy the content of a branch to a new local branch?

Tags:

git

branch

I have worked on a local branch and also pushed the changes to remote.

I want to revert the changes on that branch and do something else on it, but I don't want to lose the work completely. I was thinking of something like create a new branch locally and copy the old branch there, then I can revert the changes and continue working on the old branch.

Is there a better way than this maybe?

like image 990
serengeti12 Avatar asked Feb 21 '13 09:02

serengeti12


People also ask

How do I copy code from one branch to another?

Make sure you are in the branch where you want to copy all the changes to. git merge will take the branch you specify and merge it with the branch you are currently in. Just a note that this is going to create a merge commit which may not be what you want.


1 Answers

git checkout old_branch git branch new_branch 

This will give you a new branch "new_branch" with the same state as "old_branch".

This command can be combined to the following:

git checkout -b new_branch old_branch 
like image 79
Daniel Hilgarth Avatar answered Sep 21 '22 17:09

Daniel Hilgarth