I mistakenly worked on master branch,
How can i move my changes to my branch from master?
Thanks.
Asked
Active
Viewed 368 times
2

Talha Rahman
- 720
- 4
- 12
- 27

KoboldMines
- 428
- 2
- 6
- 21
-
merge master into your
. or cherry-pick your commits from master into your branch – Jehof Mar 14 '19 at 06:18 -
just create new branch from master branch your changes will be in new branch as well. – NVS Mar 14 '19 at 06:20
-
make new branch from local master branch and push it to remote then remove changes from master and pull changes in your branch from newly created branch then delete newly created branch. – Talha Rahman Mar 14 '19 at 06:29
-
I do not want a new branch and I have not committed changes yet. I have existing branch. Changes are not committed on master. – KoboldMines Mar 14 '19 at 06:44
-
1Possible duplicate of [How to fix committing to the wrong Git branch?](https://stackoverflow.com/questions/2941517/how-to-fix-committing-to-the-wrong-git-branch) – phd Mar 14 '19 at 09:39
-
https://stackoverflow.com/search?q=%5Bgit%5D+commit+wrong+branch – phd Mar 14 '19 at 09:39
1 Answers
3
You can run the following commands from the root directory of your repository
git reset HEAD -- . #this will unstage all the files
git stash #this will stash all the changes
git checkout <your_branch> #this will switch the branch
git stash pop #this will apply all the stashed changes in <your_branch>.
#If there are conflicts at this point, resolve them, then do the following
git add -all
git commit -am "<your_commit_message>" #this will commit in new branch.
Note: statement after #
is a comment. It doesn't belong to the command & should be excluded when executing the command.

Pankaj Singhal
- 15,283
- 9
- 47
- 86
-
Though I had another way of solving my problem, this sequence will work too! – KoboldMines Mar 15 '19 at 06:08