Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
How to Delete Branch in Github?
Next article icon

How to Delete Branch in Gitlab?

Last Updated : 05 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

When working with Git, it's common to create branches to isolate changes and work on new features or fixes. However, once a branch has served its purpose, it's often necessary to delete it to keep your repository clean and organized. In this article, we'll see the process of deleting a Git branch using Git commands locally on your machine.

Using Git Commands Locally

In this approach, we'll use Git commands in your local terminal or command prompt to delete a branch both locally and on the remote repository if necessary.

Step 1: Open Terminal or Command Prompt

Launch your terminal or command prompt application on your local machine.

Step 2. Navigate to Repository

Use the cd command to navigate to the local repository where the branch exists. For example:

cd /path/to/your/repository

Step 3. Delete the Branch Locally

Use the following Git command to delete the branch locally:

git branch -d branch_name

Replace branch_name with the name of the branch you want to delete. This command will delete the branch from your local repository.

Step 4. Push Deletion to Remote (Optional)

If you want to delete the branch on the remote repository as well, use the following command:

git push origin --delete branch_name

This command will delete the branch named branch_name on the remote repository. Ensure you replace branch_name with the actual name of the branch you want to delete.

Example

Let's say we want to delete a branch named feature-new. Here's how you can do it using Git commands locally:

1. Open your terminal or command prompt.

2. Navigate to the repository:

cd /path/to/your/repository

3. Check branch:

git branch

Screenshot-2024-04-23-183448

4. Delete the branch locally:

git branch -d feature-new

Screenshot-2024-04-23-183527

5. Optionally, delete the branch on the remote repository:

git push origin --delete feature-new

Screenshot-2024-04-23-183720


Next Article
How to Delete Branch in Github?
author
nikunj_sonigara
Improve
Article Tags :
  • Web Technologies
  • Git

Similar Reads

  • How to Delete Branch in Github?
    In Git repositories, branches are important for organizing and managing code changes, but over time, unused or outdated branches can clutter the repository. Deleting these branches helps maintain a clean and manageable codebase. In this article, we'll explore the process of deleting branches in GitH
    2 min read
  • How to Delete a Branch in Git?
    When working with Git, it’s common to create branches to isolate changes and work on new features or fixes. However, once a branch has served its purpose, it’s often necessary to delete it to keep your repository clean and organized. In this article, we’ll see the process of deleting a Git branch us
    3 min read
  • How to Delete Local Branch in Git?
    Git is a widely used distributed version control and source code management system. It effectively tracks changes to source code, enabling effortless branching, merging, and versioning. What are Local Branches? In Git, branches are lightweight pointers to commits in the repository's history. Each br
    1 min read
  • How To Delete Remote Branch in Git?
    Git is an important tool in the process of application development and is used widely in the software industry by developers to maintain the codebase. Using this developers are able to organize their codebase and manage the version history of their project. Now, as a developer, you need to know how
    1 min read
  • How To Create Branch In Git?
    Creating branches in Git is a fundamental skill for any developer. Branches allow you to work on different features, bug fixes, or experiments in isolation from the main codebase. This way, you can keep your main branch stable while making changes on separate branches. In this article, we’ll guide y
    2 min read
  • How To Change Default Branch in Gitlab?
    In GitLab, the default branch is the main working branch for your project, typically set as "main" or "master". This branch serves as the primary point for collaboration, code reviews, and deployments. However, there are times when you may need to change the default branch to reflect naming conventi
    3 min read
  • How to Check Branch in Git?
    In Git, branches are independent lines of development that allow you to work on features or fixes without affecting the main codebase. Checking branches is important for managing project history, coordinating collaboration, and ensuring smooth development workflows. This article will walk you throug
    2 min read
  • How to Clone a Branch in Git?
    Git is a popular version control system that allows developers to track changes in their code and collaborate with others. Cloning a branch in Git involves creating a copy of a specific branch from a remote repository. This article will guide you through the process of cloning a branch in Git. Table
    3 min read
  • How to Delete All Local Branches in Git?
    Git provides a powerful version control system that allows developers to collaborate efficiently on projects. Over time, however, a repository can have a lot of local branches that are no longer needed, cluttering the workspace and potentially causing confusion. The "main" is the by default branch c
    3 min read
  • How to Manage Branches in GitLab?
    GitLab is a web-based platform (like GitHub) that provides services related to the version control system of a project. Branching is one such concept of the version control system. Note: Make sure you have created a GitLab account and a repository. These are the following approaches to Manage branch
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences