Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a new branch with existing changes

Tags:

git

I've cloned a master branch of a repository and made some changes. How do I create a branch with those changes? I don't want to push any of them to master.

like image 739
user1563526 Avatar asked Dec 16 '22 21:12

user1563526


2 Answers

If you haven't committed yet:

$ git checkout -b <new_branch_name>   # create (and checkout) the new branch
$ git commit -a                       # commit to the new branch

If you have already committed (master contains your changes):

$ git branch <new_branch_name>     # create the new branch
$ git reset --hard HEAD^           # rewind master

$ git checkout <new_branch_name>   # switch to the new branch
like image 125
vergenzt Avatar answered Dec 31 '22 13:12

vergenzt


For future reference. Normally you branch off, before doing any changes. But for future reference

git stash save
git stash branch <branchname>
like image 43
datenwolf Avatar answered Dec 31 '22 15:12

datenwolf