- [Cameron] Hey, I'm Cameron McKenzie.
I'm the editor-in-chief at a site called TheServerSide.com
and follow me on Twitter too @cameronmcnz
and right now I want to talk to you about
how to delete a GitLab branch.
And in this case, I'm gonna be deleting it from the server
and then synchronizing my client environment
so that my client GitHub repository
is in sync with the server.
Got another tutorial that shows you how
to actually delete the branch from the client
and then push that deletion back to the server.
So that one's more like a remote deletion of a branch.
But on this one, I'm gonna start in the server
and then push it to the client
and the other tutorial, I'll start on the client
and push it to the server.
As with all things, we must start by logging into
the GitLab administrative console,
poking at the gitlab-made-easy project.
And in this case, I want to take a look at
the different branches in my repository,
which should include master and feature
and a whole bunch of others.
There's fun_feature, release, master,
so what I'd like to do is I'd like to actually delete
this fun_feature branch.
It's been merged into develop
and develop's been merged into master.
So I don't have any need for this particular branch anymore.
So, how do you delete a branch inside of the tool?
Well, there's a little white garbage can,
some people say it's a red garbage can, it's not,
it's a white garbage can on a red background,
details matter, and you just click that garbage can
and that fun_feature branch is now gone.
Now, some people might be wondering
how do you delete the release branch.
Notice it's protected, if you wanna do some manipulation,
like delete a protected branch, you're gonna have
to go into settings, and from settings click on repository,
from repository you're gonna have to click
on protected branches, and then you're gonna have
to find that button for the branch that says unprotect.
Now, you'll need permissions to do that.
Not anybody can do that.
So if you don't have permissions to unprotect the branch,
you're not gonna be able to delete it either.
But, yeah, if you do unprotect it
and you've got permissions to do that,
then you can delete the branch if it's protected.
So as you can see, deleting a branch,
really not all that difficult.
Now, a lot of times people aren't really worried
about deleting the branch so much as they're concerned
with synchronizing their workstation
with the deleted branch.
So for example, if I go and pretend that I'm a developer
here and I go and move into my GitLab repository
on my local machine
cd gitlab-made-easy,
do git status, currently I'm on
the release branch, that's fine.
But also if I take a look at
all of the different branches that I've got,
kind of two dashes, notice that I've still got
this fun_feature branch.
And if I do a git pull origin, says I'm already up to date,
and if I do a git branch dash a,
you notice I've still got that fun_feature branch.
So how do I actually delete that branch
given the fact that it's been deleted up on the server.
The way that you do it is you just actually do a prune
So right now I say,
Hey, I wanna do a git fetch and dash P
is the switch that you use for prune.
By the way, I got an error message earlier
when I did dash all,
two dashes for a word,
one dash for a letter.
So, here I'll do git fetch prune
and I'll just use the short form.
So single dash and P and you notice now it says
this particular file has been deleted, and if I do
a git branch dash dash all, two dashes,
'cause it's a full word, git branch dash a
because it's an alias, same command.
You'll notice that, the fun_feature is no longer there.
And so that prune command has now got rid
of that remote reference.
And now with that remote reference gone,
I can actually delete the branch locally.
And that's just a matter of issuing the command
git branch dash D and the name of the branch, fun_feature,
And now when I do a git branch dash a
you'll notice that the remote reference has gone
and the actual local branch has gone as well.
And so there you go.
That's all there is to deleting branches from GitLab
and subsequently cleaning up your local repository
so that you no longer reference that remote branch.
And there you go, that's all there is to deleting
a GitLab branch and pruning your local git repository,
and then again, that starts from the server,
that starts from the GitLab server,
deletes it on the server
and then synchronizes the workspace.
In the next tutorial,
I'll show you actually how to delete the branch
from your client machine using terminal or eclipse
and then push those changes to your remote servers.
You might be interested in that one as well.
But anyways, if you want more information on GitLab,
if you want more information on Git,
and for that matter, anything going on in the Server-side,
Microservices development, Agile, Java, you name it,
head over to TheServerSide.com
and also follow me on Twitter @cameronmcnz.