Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The clean way to make a branch in Git a posteriori

Tags:

git

github

Say you are working on a branch, and you come up with an interesting behavior you want to archive as an experimental branch. What is the cleanest way to do this?

Cleanest way I can think of off the top of my head:

1) Backup your local version to another directory.

2) git checkout, to revert back to your last commit

3) git branch experiment_name, make the new branch

4) git checkout experiment_name, switch to the new branch

5) Copy your backed up version to the working git directory.

6) git commit, commit your new fancy experimental branch

like image 680
Chad Brewbaker Avatar asked Dec 17 '22 20:12

Chad Brewbaker


1 Answers

If you don't have a clean index:

git stash
git checkout -b name
git stash pop
... more edits
git commit

If you have a clean index, you can just create a new branch off the current head:

git checkout -b name
... edits
git commit

Or if you have edits that belong to the current branch and you want to work on a new experimental branch for some time and return then:

git stash
git checkout -b name
... edits
git commit
git branch master
git stash pop
... continue work
like image 113
poke Avatar answered Dec 29 '22 22:12

poke