I have a PHP framework versioned with GIT and I'm planning several (drastic) changes to its core.
What I want to do is to start working on the new core in a new branch, but since this change might require some restructuring on the filesystem too, I'd like to start this new branch as cleanly as possible.
I want the clean branch to include only with the core files. As I'm finishing my changes, I want to add the rest of the modules from the framework to the working directory one by one, but keep the ability to merge if I do changes on master.
How can I do that?
To create a branch from some previous commit, you can use the git-branch command. This creates a new branch, branchname which whose head points to specified commit-id . For example, the following creates a develop branch from the specified commit hash.
You should create a new branch when you're doing development work that is somewhat experimental in nature. So in your scenario definitely create a new branch and not a folder within master. If you created your sandbox work as a directory in the master, it's going to reside there until you remove it using git.
You want the --orphan flag. For example:
git checkout master
git checkout --orphan foo
# Unstage all the files in your working tree.
git rm --cached $(git ls-files)
will create a new branch named foo with no ancestors, but it will preserve the current working tree from whatever branch you were on when you called the command (in this case, the master branch). You can then modify your working tree to suit, and then make a commit to start that branch's history afresh.
To perform incremental additions to your history, use git add
to stage just the files you want for each commit. The git-add(1) manual page has this to say about adding files selectively:
Fileglobs (e.g. *.c) can be given to add all matching files. Also a leading directory name (e.g. dir to add dir/file1 and dir/file2) can be given to add all files in the directory, recursively.
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