I have 100s of changes that I don't want to push to master. Usually I start a new branch, and then merge later.
How can I create a new branch without losing my current changes?
I have 100s of changes that I don't want to push to master. Usually I start a new branch, and then merge later.
How can I create a new branch without losing my current changes?
To Save all changes in new branch without losing any data First stash changes
git stash -m "write_your_own_message"
Make your new branch
git checkout -b "new_branch"
And get all changes in the current branch by this command
git stash apply
If you have more than one stash run this command to know stash number
git stash list
And have a stash list like this
stash@{0}: On master: all chages in the files
stash@{1}: WIP on master: 44381e5 add files project
stash@{2}: On master: my changes
Apply stash by index number like this
git stash apply 0
Using visual studio
origin
side).Just do
git stash -m "my awesome changes"
After creating a new branch, just apply
git stash apply --index 0
If you have other stashes, then make sure you use the right index.
If you have been making local changes, and you want to commit them to a new branch, just create the new branch and add them to it. It's ok to create a branch when there are uncommited changes present.
e.g.
On branch main: Change 7 files. These changes are not committed.
git checkout -b my_new_branch
git add names-of-files-changed
OR
git add -u (means add any files which are in the git repo, but have changed. Does not add newly created files)
git commit -m"message describing changes"
main is where it was before your changes. my_new_branch has your changes.