Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git create branch from current checked out master?

There is a git controlled folder on a server where the main branch is checked out and a whole pile of files have been modified and not committed. Is there a way for me to commit the changes to a separate branch so I can go back to a clean version?

ie I want to effecitvely undo all this persons changes but store them in another chance so if that person wants their changes they can switch to that branch.

(Yes I know this is not how git is designed to work but that is my situation!) Any ideas very much appreciated.

like image 641
corydoras Avatar asked Sep 21 '09 06:09

corydoras


People also ask

How do you create a new branch from currently checked out a branch?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

Can I create a new branch with current changes?

You can do a checkout and create a new branch with all local and current changes transferred over.

How do I create a checkout branch in git?

To create a new branch there is a git branch command. After you have created a branch, you need to switch in this branch using a git checkout command. But it is also possible to create a new Git branch and switch in this branch using only one git checkout command with -b option.


1 Answers

First of all moving to a different branch based in the current HEAD is performed like this:

git checkout -b newbranch 

Commit all the changes (assuming no newly added files, otherwise git add them):

git commit -a 

Go back to the master branch:

git checkout master 

The previously uncommitted changes will all be on the newbranch branch, and master will still be at the state it was without those changes.

like image 144
CB Bailey Avatar answered Nov 16 '22 01:11

CB Bailey