creating git branch after the fact?

天大地大妈咪最大 提交于 2019-12-04 08:02:52

问题


I suspect the answer to my problem is fairly simple, but I'm a git newbie and my head is getting confused at reading answers to all the similar SoF questions that don't seem to be quite my problem.

Here's my problem:

I have a repo at github with a single branch ('master') that I've been working on in my local repo. At some point I stopped pushing commits back up to master on github because I was worried that they'd break things. So now I have lots of commits in my local repo that I want to push back up to github.

However, rather than pushing back up to master I would prefer to create a new branch on github ('development') and push all my local commits back up to that branch (which I will merge back into master only after they've been better tested).

What is the simple way to do this?


回答1:


on master:

git checkout -b newbranch or as suggested below, simply do a git branch newbranch to create the new branch without switching to it.

This will create a branch that is at your current commit at master. Once done:

git checkout master

followed by:

git reset --hard <commit_hash>

Where <commit_hash> should be replaced by the commit ID you want master rolled back to.

Now you can switch to your new branch and push it out to the remote.

git checkout newbranch
git push origin newbranch


来源:https://stackoverflow.com/questions/5343372/creating-git-branch-after-the-fact

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!