user842225
user842225

Reputation: 5989

move the uncommited change to another branch

I have made some changes in project, but I didn't commit the changes. They are in the state of

Changes not staged for commit

. Then I realised I should make these changes in a separate branch than the current one.

How can I create a new branch which can have my current changes while remove the uncommitted changes in current branch?

Upvotes: 1

Views: 73

Answers (2)

Sebastian Stigler
Sebastian Stigler

Reputation: 7289

You can type:

git checkout -b NEW_BRANCH_NAME
git add .
git commit -m "PUT YOUR COMMIT MESSAGE HERE"

git checkout -b ... creates a new branch and checks it out in one step.

Now you can use git checkout master to go back to the master branch.

To merge your code into the master branch:

git checkout master   # if you are not already in the master branch
git merge NEW_BRANCH_NAME

Upvotes: 0

Master Slave
Master Slave

Reputation: 28529

Just checkout a new branch, commit within the new branch, and checkout the original branch. This way the changes will be in a separate branch only.

Upvotes: 2

Related Questions