开发者

Create branch from current working tree and reset to HEAD

I currently work on a feature that turns out to be bigger than expected, so it's probably the best to create a branch to work on it. So I need to create a new branch from my current working dir开发者_如何学运维ectory and reset the master branch to the current HEAD so that some fixes to the production environment can be done.

Somehow this sounds like an easy task, yet I can't quite figure it out. Possibly due to my lack of sleep.


So, create a working branch:

git checkout -b working_branch

either commit or stash your changes

git add <files>
git commit -m "message"

OR

git stash

Go back to master

git checkout master
git reset HEAD


If you haven't yet made a commit then you don't need to move master, it's already at the current HEAD. You can just checkout a new branch with checkout -b, it doesn't need your working tree to be clean.

E.g.

git checkout -b newtopic

You are now on newtopic and can commit your working tree changes here. master doesn't need to move.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜