Yesterday’s tip visualized what happens in Visual Studio (and in Git) when you create a branch. Today’s tip visualizes committing code independently in different branches.
First, you’ll see how to commit to separate branches in Visual Studio, then we’ll rinse and repeat in the Git Visualization tool.
Committing to Different Branches in Visual Studio
In this example, I’ve rolled back to the Console Application with only output message. We’re going to add the ChangeColor() method and call on a branch called addColor.
Once you’ve pressed Commit All to addColor, you’re going to discover that you want to experiment with decorations. You can use Team Explorer – branches to create a new branch called decorations.
You’ll want to use master because you want to keep the addColor changes separate from your decorations branches.
and you’ll want to verify you were on master in the dropdown
Add your decorations to your project file
And now commit those changes to your decorations branch.
And now we have 2 different commits on 2 different branches
Visualization of what we just did
First, we’ll want to create and checkout a branch called addColor and make some changes there.
Next, we’ll want to switch back to master and create a new branch from there.
Finally, we’ll make a commit on the decorations branch.
I keep trying to remind myself that whenever I do a checkout, reset, etc. I’m not really going forward and backward in time, but rather I’m moving to a different nodes on a graph. Visualizing what git is doing helps break my timeline mental model.