Hey everyone so this is Part 2 of a series
of videos I've compiled of popular Git commands and how
they're executed in V code.
This time we are covering managing branches like creating, listing,
switching, renaming and deleting branches. So check it out. Two
common commands to create a branch include Git branch and
Git checkout. Git checkout- be followed by the branch name
creates and checks out a new branch while Git branch
followed by the branch name creates a new branch.
But leaves you on your current branch. So let's see
what command Visual Studio code uses when we use its
UI to create a branch. Now here I have an
index HTML file that I've already staged and committed, and
on the bottom left hand corner you could see that
we're currently on our main branch. But to create a
branch I will simply hit the shortcut shift command P
here since I'm on a Mac and I will choose
create branch, I'll give it the name.
Staging branch.
And let's create another one called testing branch.
And to see what Visual Studio code did on the
back end. If we check the git output we could
see on the first line Git checkout was used to
create staging branch and a little later on it was
used again to create testing branch.
When you're using Git, in order to list your branches
to Git Branch command is used. But with this code,
in order to list the branches that we're working with,
all we need to do is click on the bottom
left hand corner, the current branch that you're on, and
then on the top of the screen you'll get a
list of our local branches. In order to switch between
branches, 2 commands that can be used include Git switch
followed by the branch name and also Git Checkout followed
by the branch name in terms of.
Switching branches. Both are effective, but I do encourage you
to check out the official Git documentation for the history
of these two commands, which is beyond the scope of
this demo. But to see how to switch between branches
in VS code, all we need to do is hop
on to the bottom left hand corner where our current
branch is, and right now we are on the testing
branch. If we wanted to go to staging branch, just
select it.
At the top of the screen.
And now you see that staging branch is what's current.
And if we scroll up to the beginning of the
git output, you see that Git checkout was used to
switch to staging branch. In order to rename a branch,
we use the Git Branch Command followed BY-M and then
the branch name and vscode. All we need to do
is use our shortcut shift Command P select rename branch
and let's rename this to staging 2 branch.
And if we hop on over to our output, we
could see that on the first line Git branch was
used in order to rename our branch. When deleting a
branch in Git, the command that we use is Git
branch followed by A-D and the branch name. Now in
Visual Studio code, if we wanted to, let's say delete
this branch here called staging 2 Dash Branch, which is
really not a great name, we can switch over to
another branch and then.
Using the command palette.
We have an option to delete branch and at this
point I can select staging 2 branch and if we
look at our git output you can see on the
first line the Git Branch command was executed. So that's
it. If there's other git commands that you'd like covered
in future videos, drop them in the comments and if
you got some value out of this, don't forget to
like and subscribe catch you in the next one.