I have a repo on 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. 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?
Generally create a branch for every feature you're working on. Commit all your changes there. Then when you're done, merge it (pull request or not) to wherever it needs to go.
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!
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With