Reputation: 1077
I've ended up making a whole bunch of changes in my local repo but unfortunately I had cloned the master branch and not a development branch like I had meant to.
Is there a way of creating a new branch from these changes and ensuring I leave the remote master untouched?
We have git self hosted if that makes any difference
Upvotes: 0
Views: 903
Reputation: 20457
Yes, this is trivial, so long as you haven'r pushed the changes to the master branch on the repo you cloned from (it's fine if you committed them locally).
If you have changes but you haven't committed them, just create a new branch before you commit them.
$ git checkout -b my-new-branch
$ git commit -a # or git add or whatever is needed for your changes
If you have committed changes on the master branch of your local repo, just make a new branch at the same point, and reset master back to where it should be:
$ git branch my-new-branch
$ get reset --hard origin/master
$ git checkout my-new-branch
If you've committed and pushed changes, then fixing it will first involve finding out whether anyone else has pulled those changes.
Upvotes: 2