2

I'm working on my current master and have done quite a few changes which are as of now neither locally nor remotely committed. However, I am ready to commit them. Before doing so I would like to turn the current master without these uncommitted changes into a new branch but I am not completely sure what the right procedure for this is. My first idea was to do a clean clone in a different directory

git clone REPO 

and then initialize a new branch from the current master

git checkout -b OLD_MASTER 

and then commit. Then go back into the other clone which contains the uncommitted changes and commit them. But that seems unclean to me. What is the right way to achieve my goal?

3
  • I must ask, why do you need this? Git maintains history of the master branch for you, and if you need to revert, you should revert back to that commit. You should also look into tagging so you can version your releases properly. Commented Apr 6, 2015 at 17:28
  • I know, I'm just for failsafe redundancy. Also, I might have to have the current master available extremely fast without reverting commits first. Commented Apr 6, 2015 at 17:32
  • "turn the current master [...] into a branch" doesn't really make sense, because master already is a branch. Also doing git checkout -b OLD_MASTER and then committing will make OLD_MASTER point to a new commit which has nothing to do with the old master, so that doesn't make sense either. I'm not really sure what you're trying to achieve here; please could you clarify the use case or end goal? Commented Apr 6, 2015 at 23:36

1 Answer 1

4

You can create the branch and go back to master:

git stash git checkout -b old_master git checkout master git stash pop 

But don't you want a tag instead?

git tag old_master 
Sign up to request clarification or add additional context in comments.

8 Comments

The stash is redundant. You only need the git checkout -b new_branch.
@AdamSpiers "I would like to turn the current master without these uncommitted changes into a branch" meaning OP doesn't want the changes to come into the new branch.
I've edited but I'm still not sure I got the full problem. It might be a tag is more appropriate.
Thanks for the tag-reminder @sjagr and Fancis Colas. I used that as well as the stash-based solution.
Not necessary, I agree; but useful in the case where you want to pull changes from a remote (which you'd do once you're back on master).
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.