I made some experimental change to my master branch, then I'd like to make some quick fix which is independent with the change in my master branch. I tried create a new branch, but it seems it is based on my master and I have to undo the experimental changes at first. How to I create a branch which is based on the master branch I forked from?
Asked
Active
Viewed 1,620 times
1
-
2`git checkout -b new_branch_name origin/master` – Rob W May 24 '15 at 15:39
-
1Checkout the commit you want to branch from, then create a branch. – May 24 '15 at 15:41
-
2The main problem is that you're doing experiments in the master branch. Experiments should be done in a topic branch. I would create an experiment branch from master, then reset master to the latest non-experimental commit (i.e. probably to origin/master), then create a fix branch from master. – JB Nizet May 24 '15 at 16:01
-
1Related: http://stackoverflow.com/questions/25933056/how-can-i-do-a-bugfix-on-master-and-integrate-it-into-my-less-stable-branches – jub0bs May 25 '15 at 09:11
1 Answers
2
A new branch is only created from the current branch by default. You can specify any commit to base the branch on with. For example, if your history looks like
* -- A -- B -- C (master)
and B
and C
are your experimental commits, then run
git branch bugfix A
to create a new branch that starts at commit A instead of commit C.

chepner
- 497,756
- 71
- 530
- 681