Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create branch with N-last commits

Tags:

I have cloned repository and have made some commits:

git clone ... git add git commit git add git commit git add  git commit  

Now I have realized that it will be better to move all my commits to another new branch. What is the best way to do it?

like image 288
ceth Avatar asked Jun 18 '11 18:06

ceth


People also ask

How do you create a new branch from a previous commit?

First, checkout the branch that you want to take the specific commit to make a new branch. Then look at the toolbar, select Repository > Branch ... the shortcut is Command + Shift + B. And select the specific commit you want to take. And give a new branch name then create a branch!

How do I create a new branch in git?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.


1 Answers

Easy, check out your new branch, then move the old branch (let's assume master and 3 commits were made) back:

git checkout -b my_new_branch git branch -f master HEAD~3 
like image 129
knittl Avatar answered Sep 23 '22 22:09

knittl