Branching and merging
So far, we have been adding changes sequentially to the repository, resulting in a history with a linear structure. But what if you, or your team, want to work on different features/multiple tasks at the same time? If we continue with our current workflow, the Git commit history is going to look disjointed:
Here, we have commits relating to bug fixes interleaved between commits relating to features. This is not ideal. Git branches were created to deal with this issue.
Git branches
As we've briefly mentioned, the default branch is called master
, and we've been adding commits to this branch up to this point.
Now, when we develop a new feature or fix a particular bug, rather than adding those commits directory to master
, we can instead create a branch from a certain commit from master
. Any new commits to these bug fix and/or feature branches will be grouped together in a separate branch in the history tree, which does not affect the master
branch. If and when the fix or feature...