- from the master branch create a feature branch called
feat1
git checkout master
->git checkout -b feat1
-
git add .
-
git commit
-
From here we'll start the process of splitting the commits across multiple branches. To do this we'll create another feature branch
big_feat1
based off of the original feature branchfeat1
This command creates a new branch called big_feat1
based off of feat1
and checksout the new branch (big_feat1)
git checkout -b big_feat1 feat1
The following command will unstage the changes that were pulled over from the original brach so we can review and commit them across other branches. (FYI this leaves the originalfeat1
branch unchanged)git reset master
git status
Here we'll use the patch option for git add. We use patch so that we have more control over the specific changes we're adding within each file. In case we have changes that need to be added through various commits in a single file.
git add --patch
- use the y command to just add everything
- use the s command to split the file's changes into various commits
- there are many other options as well. Each depend on the use case
Before committing the changes stash the reset of the changes that we'll add and commit later
git stash --include-untracked --keep-index
- --include-untracked will include new files as well
- --keep-index will tell git to not mess with your already staged changes from the previous step
git commit
git push origin big_feat1
Now we have our first branch ready for review we can start to create the second branch
git checkout -b big_feat2 big_feat1
git stash pop
- from here just follow the same steps listed after we created the first branch.
- use git merge to resolve merge conflicts across all the stacked braches. If you use rebase you'll have to resolve the same conflicts in all of the stacked branches.
Thats it!