It seems that I have to write these tips in triplicate: 1. command line, 2. Visual Studio, 3. git visualization tool. But that’s been the only way to prove to myself I’m grasping the concepts.
A college French professor once gave me the advice to never use contractions in class unless I was prepared to never ask him to slow down. I had just learned the equivalent of “I do not know” vs “I don’t know” (something like that).
Applying that advice to software, I don’t want to start using git shortcuts by combining commands until it is clear what the two commands are independently doing. (Yep, I’ll show the shortcut in a second… )
First, you’ll want to create a branch:
> git branch my-branch
Next, you’ll want to switch to that branch:
> git checkout my-branch
Okay that’s pretty straight forward, but what’s happening conceptually?
We are on master when we created a branch called addColor while on master and then switched to addColor.
The take home message is that addColor has everything that master has because we created the branch addColor while on Master.
Git Command Line Shortcut
Before we jump into the IDE, let’s take a sneak peek at that shortcut.
Note: in case anyone is following along at home, I first switch back to master to delete the addColor and then recreate using the shortcut.
The shortcut is
> git checkout -b addColor
This shortcut says to checkout to addColor and if it doesn’t exist, create it.
When you’re in Team Explorer, you can go to Branches, right click on the branch you want your new branch to be based on, right-click, and select New Local Branch From…
Then give your new branch a name (and verify in the drop down you picked the correct branch) and leave the checkbox checked…
If you have the Checkout branch checkbox, you’re telling VS to create the branch and do the checkout so you’re now on the addColor branch instead of master.
If you uncheck it, it is the equivalent of creating the branch on the command line, but staying on master.
To confirm you’ve created and switched to the addColor branch, you’ll see that addColor is now in bold.
And the branch is also shown in the Visual Studio status bar.