Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert local master into a branch in git

Tags:

git

github

I cloned a github repository and made several commits locally. I accidentally made these commits on the master branch when I had intended to make a separate branch for my changes. Is there some way to turn these changes into a new branch and restore the original master branch before I push my changes to the remote?

like image 331
mushroom Avatar asked Jun 13 '13 03:06

mushroom


People also ask

Can I merge master to branch?

The steps to merge master into any branch are: Open a Terminal window on the client machine. Switch to the feature branch. Use git to merge master into the branch.


1 Answers

  1. # create a new branch from your current HEAD:

    git branch <newbranchname>
    
  2. # reset your current branch (still master) to the remote master branch:

    git reset --hard origin/master  
    
  3. # switch to the new branch:

    git checkout <newbranchname>    
    
like image 159
nneonneo Avatar answered Sep 20 '22 15:09

nneonneo