A clean way to make a branch in Git Posterior

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

The cleanest way I can think of from my head:

1) Make a backup of your local version to another directory.

2) git to return to the last commit

3) git branch_name, enter a new branch

4) git check instance_name, switch to a new branch

5) Copy your backup to the git working directory.

6) git commit, transfer a new fantastic experimental branch

+4
source share
3 answers

Just git checkout -b experiment_name and commit.

+5
source

If you do not 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 simply create a new branch with the current head:

 git checkout -b name ... edits git commit 

Or, if you have changes related to the current branch, and you want to work on a new experimental branch for a while and return:

 git stash git checkout -b name ... edits git commit git branch master git stash pop ... continue work 
+6
source

For very temporary things, maybe git stash .

+1
source

All Articles