Git Crash Course #14 - Deleting Branches
Skills:
Tool Use & Function Calling80%
Key Takeaways
The video demonstrates how to delete branches in Git, including how to delete a merged branch and a branch with unmerged commits, using the git branch command with the -d and -D flags.
Full Transcript
Okay then. So, we've just done our first merge and now we've got our newsletter feature integrated into the main branch. But if we look at our branches, we've still got that feature newsletter branch hanging around. We've also got the old my new branch that I created earlier as a test. And generally speaking, it's a good practice to clean up branches once you're done with them so they're not sitting around causing any kind of clutter. And I speak from experience when I say that having tens of branches lying around makes things a little confusing. you start to lose track of what's active work, what's not, and just having loads of stale branches makes it harder to stay organized. And this becomes even more true when you start to work in a team of developers all working on their own branches. So, in this lesson, we're going to see how to delete all branches when we don't need them anymore. And it's pretty simple to do. So, let's start with this newsletter feature branch, then since we already merged it into the main one, and we don't need it anymore. Now, importantly, in order to do this, we first of all need to make sure we're not currently on the branch we want to delete. I'm on main, so that's okay. But if you're on the feature branch, use the switch command to switch back to main before you try and delete the feature branch. So then now let's try deleting it by running the command get branch and then the hyphen d flag, which stands for delete. Then the name of the branch we want to delete, which is feature- newsletter. And once we run that, it's going to go ahead and delete that branch for us. Now, you can verify that by running the get branch command again to see all the current branches that you have. And you're going to see now that the feature one isn't there. Awesome. So then now let's try deleting the other branch that we don't need anymore. Now before we do that, I'm going to switch over to it by running the command get switch and then the name of the branch, which is my new branch. Not so new anymore. Okay. And this branch is now actually behind the main one because we made it back before we merged the newsletter feature into main. So before we delete this branch, I want to show you another pattern you might follow, which is to make a branch, start working on it, make a commit or two, and then maybe decide that you don't want that work anymore or you don't want that branch anymore. And we don't merge it back into main or anything. We just want to delete it. So then I'm literally just going to open the homepage file and then add a character into the title or something just so we've got something to commit. I'm going to save the file and then we want to add the change to the staging area by running the git add command then a dot and then press enter. Now I'll commit that change by running git commit along with the m flag to add a commit message which can be something I don't know like update homepage title. Okay. and then we can run it. So now we have a commit in this branch and now let's say we don't like it anymore. The feature is complete trash. We want to get rid of it. Well, let's do that. The first step again is to jump off the branch because we can't delete a branch if we're standing on it. So let's switch to the main branch by running the get switch command followed by main to jump to the main branch. And now let's try deleting that other branch that we just jumped off by running that same command as before, which was get branch. And then we use the hyphen d flag to delete one followed by the branch name which is my new branch. Now when we try to run this, git won't let us and it says instead that the branch is not merged. So this is git's way of protecting us from accidentally deleting a branch that we might not want to do and losing work essentially because that branch does have a commit on it now which hasn't been merged yet. So when we want to delete a branch with commits on it which haven't been merged, we need to change the delete command just a little bit to force the delete and all we need to do is change the small case lower D flag to an uppercase one. And that's you basically telling it look I know there's work on this branch that hasn't been merged but I still want to delete it. So let's run this command then. It's get branch and then this time hyphen D but uppercase D and then the branch name which is my new branch. And when we try to delete it this time it works. Git will delete that branch. And we can confirm that by running git branch and hitting enter to show us only the main branch is left. Okay. So that is how to delete branches. And again, it's always a good practice to get into when you're finished work on a branch so that your repo doesn't turn into a graveyard of old work and old branches. All right, then my friends. So, that is the end of the git crash course and the end of the preview of the whole Git and GitHub masterclass course that I released on the net.dev site. So if you want to carry this on and there is about another 5 hours of content all about Git advanced features uh GitHub using AI with GitHub as well the GitHub CLI then feel free to go and grab this course on the netinja.dev website. I will leave a link to the course page down below. It's $10 to buy or you can use the promo code which is get40 to get it for $6. And you can also sign up for a Net Ninja Pro subscription by clicking on this link right here. And that's going to be $9 a month to get access to all of my masterclass courses, including this one. And also, you get your first month half price. So, I really hope you've enjoyed this series so far. If you have, please do not forget to share, subscribe, and like. That really means a lot. And hopefully, I'm going to see you on the full one soon. Heat. Heat. N.
Original Description
In this Git tutorial series, you'll learn how to get up and running with Git in your own projects. You'll learn how to setup a repository, stage & commit changes, revert changes and how to use branches to work on new features.
🔥🥷🏼 Get instant access to the WHOLE Git & GitHub Masterclass:
https://netninja.dev/p/git-github-masterclass
🔥🥷🏼 Get instant access to ALL premium courses on NetNinja.dev:
https://netninja.dev/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
More on: Tool Use & Function Calling
View skill →Related Reads
📰
📰
📰
📰
I Did the Math on Claude Opus 5: Max Effort Cost 94% More Than High Effort
Dev.to · tokenmixai
I Banned AI Tools From My Creative Process for 30 Days. Here’s What Happened to My Brain
Medium · AI
Best AI Tools for Content Creators With Zero Budget
Medium · AI
Stop Building AI Chatbots. Build These 7 AI Products Instead.
Medium · Machine Learning
🎓
Tutor Explanation
DeepCamp AI