Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
The course shows how to use Git, the popular open-source version control software, to manage changes to source code and text files. Using a step-by-step approach, author Kevin Skoglund presents the commands that enable efficient code management and reveals the fundamental concepts behind version control systems and the Git architecture. Discover how to track changes to files in a repository, review previous edits, and compare versions of a file; create branches to test new ideas without altering the main project; and merge those changes into the project if they work out. The course begins by demonstrating version control in a single-user, standalone context, before exploring how remote repositories allow users to collaborate on projects effectively.
In this movie, we are going to learn how to delete a remote branch. Essentially, what we are going to do is be able to tell GitHub that it should erase one of the branches in its repo. First, let's decide what branch we want to get rid off. You can see that I am inside my lynda_version folder on the master branch, if I do git branch -a, you can see that I have got this non_tracking branch locally, and I have also got non_tracking up on the remote repository. That's the one that I want to tell GitHub to delete. There are two ways that we can do this. First, I want to show you the older and less intuitive way, then I will show you a newer one after that.
The first way is to use git push and just like we did before when we are using git push, we push to the remote, and when we did it before, we did it like this, we said, push the contents of non_tracking up it the server. In order to delete it, you put a colon in front of it. Git push origin, and a :non_ tracking will have the effect of deleting the branch on the remote server. Let's try it. So it wants my username, my password, it comes up, and it says that it deleted it, and now if we say git branch -r, you can see that it's gone, and if we go to GitHub, if you have Firefox, reload the page, and sure enough under Branches, you can see that we only have a master branch now.
Now notice that if I do git branch for my local branches, it's still here. All I did was a push up to origin, I didn't do anything to my local branches, so I still have all that information. Why this awkward non-intuitive way of doing it? What's the colon all about? Let me give you some insight into that. When we did our original push of the branch up to origin, we did it like this, git push origin/non_tracking. That's actually shorthand for git push origin non_tracking:non_tracking.
What this is saying is push to origin my local branch non_tracking, to the remote branch called non_tracking. That's what it's doing. When we only have one, it assumes that they are the same, which they often are. But this colon divides those two. So when we are doing a delete, what you are actually doing is saying, push to origin nothing up to the branch non_tracking. So that's why that colon is there. That's where it comes from. But that's not very intuitive.
Let me show you the newer way, this is a little easier to remember. First, let's push that branch back up there again, remember it is going to push my local branch non-tracking up to the remote repository, so there it is now, git branch -r, you can see it's there. Now let's do another delete, git push origin again, but this time it's --delete and then non_tracking. It requires a little more typing, but it is a little easier to remember, a little more intuitive. So now we hit Return.
It's going to want me to log in again, and once again, it's deleted it. So there it is now it's gone. So that's all there is to being able to delete a remote branch.
Find answers to the most frequently asked questions about Git Essential Training.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.