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.
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.
You can do a checkout and create a new branch with all local and current changes transferred over.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With