Skip to main content

GitKit (Linux Desktop Edition): Learn git and GitHub in Context

Section 4.6 Deleting a Feature Branch

Once your changes have been merged into the upstream main, and you have synchronized, there is no need for you to retain your feature branch. There is no harm in keeping it. But most developers will delete them to avoid having their repos become cluttered with old feature branches.
Cloud image of the feature branch.
Figure 4.6.1. Deleting Feature Branches.
Figure 4.6.1 shows the state that will result after deleting the feature branch from your local and origin repositories.

Exercises

1.

The first step is to delete the feature branch from your local repository. This exercise will walk you through that process.
(a)
    It is not possible to delete the active branch. So, if you have not already, switch from your feature branch to the main branch. Then give a command that lists all of the branches in your local repository.
    Which command did you type to list the local branches?
  • git switch
  • The git switch command is used to change the active branch.
  • git pull
  • The git pull command is used to pull changes from a remote repository to your local repository.
  • git commit
  • The git commit command is used to commit staged changes to the repository.
  • git branch
  • Correct! The git branch command is used to display all of branches in your local repository.
Hint.
Refer back to the section on switching branches Section 3.3
(b)
    From the output provided by Task 4.6.1.a how do you know which is the active branch?
  • It has an * next to it.
  • It appears in green.
  • It appears in bold.
  • It appears in italics.
  • It is not possible to tell the active branch based upon the output provided.
Hint.
Refer back to the section on switching branches Section 3.3
(c)
The command git branch -D <branch> will delete a branch from your local repository. Use the this command to delete your feature branch.
(d)
How can you check if your branch was deleted? Be sure to check that it was deleted. If not return to Task 4.6.1.b and try again.

2.

In the previous exercise you deleted your feature branch from your local repository.
(a)
    This feature branch no longer exists in your origin repo on GitHub.
  • True.

  • You have only deleted the feature branch in your local repository. It still exists in your origin repository on GitHub.
  • False.

  • You have only deleted the feature branch in your local repository. It still exists in your origin repository on GitHub.
Hint.
Make sure you look at your repository on GitHub and click the "Branches" link.
(b)
Explain how you know whether the feature branch exists in your origin repo on GitHub?
(c)
You can delete your feature branch from your origin repo using the git CLI. The command
git push -d <remote repo name> <branch>
will delete the specified branch from the specified remote repository. Use this command to delete your feature branch from your origin repo.
(d)
Use your browser as you did in Task 4.6.2.a to confirm that your feature branch is deleted from your origin repo on GitHub. If it has not been deleted, revisit Task 4.6.2.c and try again.
You have attempted of activities on this page.