Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - Forgot to switch branch

I forgot to switch to a new branch before beginning my project, and now I need to push my changes to a new branch (not master) in order for another to review my work. My work is finsihed, but saved in my local master.

How can I move my changes into a new branch, so when I push it doesnt mess with the master branch but instead create a new remote branch ?

like image 906
Kim Avatar asked Apr 26 '12 13:04

Kim


2 Answers

First, since you have done all your work your local master branch, create a new feature branch pointing to the tip or your local master.

$ git checkout -b newfeature master

and then leave the master as it is in the server (remote)

$ git checkout master
$ git reset --hard origin/master
like image 191
KurzedMetal Avatar answered Sep 22 '22 19:09

KurzedMetal


Create a new branch at the same point as your master.

Checkout the master, and hard reset your current branch to the commit you want to rewind to.

like image 20
Khanzor Avatar answered Sep 25 '22 19:09

Khanzor