Reputation: 1358
I have some code that i want to commit into another branch, however i did the changes before create the branch, so now I'm in master and I want to stash the code, create a local branch, checkout it, and then stash the code into that new branch so i can commit within it.
Would this work ?
$>git stash
$>git checkout -b newversion
$>git stash pop
$>git commit -m 'new version'
You should think 'Hey dude just do it and check if works' , well, there are a lot of files so I don't want to mess it up, Any help on this will be so helpful.
Thanks.
Upvotes: 2
Views: 144
Reputation: 3687
Your solution will work as expected, but you can accomplish the same result without using git stash
. If you just have made some modifications which must be committed on a new branch, it is enough to run only 2 of 4 commands:
git checkout -b newversion
git commit -a -m "new version"
Upvotes: 1
Reputation: 141976
here you can view it in a visual way: http://ndpsoftware.com/git-cheatsheet.html#loc=stash;
Upvotes: 1
Reputation: 239250
Yes, of course that will work. That's exactly the sort of thing git stash
is for. You're not actually even changing the working directory, you're just assigning an additional name ("newversion") to the currently checked out commit. There is literally no possible way this could fail or result in conflicts.
Also, you really should "just do it and check if works". Doesn't matter how many files, once you've stashed them you have them. If things go awry, you can start over.
Upvotes: 2