Skip to content
- Courses
- DSA to Development
- Newly Launched!
- Master Django Framework
- Become AWS Certified
- For Working Professionals
- Data Science Training Program
- JAVA Backend Development (Live)
- DevOps Engineering (LIVE)
- For Students
- Placement Preparation Course
- Data Science (Live)
- Master Competitive Programming (Live)
- GATE Exam Courses
- GATE 2025 Crash Course (LIVE)
- All Courses
- Tutorials
- Data Structures & Algorithms
- DSA for Beginners
- Data Structures
- Arrays
- Matrix
- Strings
- Linked List
- Stack
- Queue
- Tree
- Generic Tree
- Binary Tree
- Binary Search Tree
- AVL Tree
- B Tree
- B+ Tree
- Red Black Tree
- Tree Data Structure Tutorial
- Heap
- Hashing
- Graph
- Set Data Structure
- Map Data Structure
- Advanced Data Structure
- Data Structures Tutorial
- Algorithms
- Analysis of Algorithms
- Searching Algorithms
- Linear Search
- Binary Search
- Searching Algorithms Tutorial
- Sorting Algorithms
- Selection Sort
- Bubble Sort
- Insertion Sort
- Merge Sort
- Quick Sort
- Heap Sort
- Counting Sort
- Radix Sort
- Bucket Sort
- Sorting Algorithms Tutorial
-
-
- Full Stack Course
- 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
Last Updated : 05 May, 2024
Comments
Improve
Gitis a widely useddistributed version controlandsource 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 branch represents an independent line of development, allowing for parallel work on different features or fixes. Local branches are branches that exist only in your local repository and are not shared with others until you push them to a remote repository.
Steps to delete a branch
Step 1: To get all local git branches in your project via the CLI
git branch
git branch
Step 2: To delete a branch locally type
git branch -d <branch name>
Sometimes git refuse to delete local branches when it contains commits that haven’t been merged into any other local branches or pushed to a remote repository. Hence, for forcefully delete a branch type
git branch -D <branch name>
By following these steps you can easily delete local branch in git.
Next Article
How to Delete All Local Branches in Git?
Please Login to comment...
Similar Reads
How to Compare a Local Git Branch with its Remote Branch ? When working with Git, it's often necessary to compare your local branch with its remote counterpart to understand the differences in terms of commits and changes. This helps in keeping your local work in sync with the remote repository and managing potential conflicts. This article will guide you through various methods to compare a local Git bran 3 min read How To Replace Local Branch With Remote Branch in Git? Managing branches in Git can sometimes require drastic measures, such as replacing a local branch entirely with its remote counterpart. This can be useful in scenarios where the local branch has diverged too much from the remote branch, leading to complexities that are easier to resolve by completely overriding the local branch. This article will g 4 min read How To Find Out Which Remote Branch A Local Branch Is Tracking? Git is a powerful version control system that allows developers to manage and track changes in their code repositories. One of the key features of Git is its ability to track relationships between local and remote branches. Knowing which remote branch a local branch is tracking can help you manage your workflow more efficiently, especially when col 3 min read Git - Create a Branch From Another Branch Branching in Git allows developers to work on isolated features or fixes without affecting the main codebase. However, what if you need to create a new branch based on the changes in another branch? That's where the concept of branching from another branch comes into play. In this guide, we'll see the process of creating a branch from another branc 3 min read How to Make an Existing Git Branch Track a Remote Branch? Managing branches in Git can sometimes be confusing, especially when you need to make an existing local branch track a remote branch. This process ensures that your local branch can easily fetch updates from and push changes to the corresponding remote branch. In this article, we will walk through the steps to set up tracking for an existing Git br 3 min read How to Make the Current Git Branch a Master Branch? Managing branches effectively is a key part of using Git for version control. Occasionally, you might find yourself in a situation where the current branch you're working on should be the new master branch. This could be due to the current branch evolving to become the main line of development, or simply a restructuring of your project's branch str 3 min read How to Replace Master Branch with Another Branch in GIT? In Git, the "master" branch traditionally serves as the primary development branch in many repositories. However, there are situations where you might want to replace the contents of the "master" branch with those of another branch. This could be due to a variety of reasons, such as renaming the default branch to something more inclusive or reflect 2 min read How to Create a Branch In Git from Another Branch? Branching is a fundamental aspect of version control systems like Git, which helps developers work on multiple features or bug fixes simultaneously without interfering with the main codebase. Creating a branch from another branch is a common practice, especially when you want to build upon existing work or isolate changes for a specific feature. In 3 min read Git Merge Hotfix Branch Into Feature Branch When working on a software project, you may encounter situations where a hotfix needs to be applied to a feature branch. A hotfix typically addresses urgent issues in the codebase that need immediate attention and correction. Integrating these changes into a feature branch ensures that the fixes are incorporated into ongoing development, maintainin 4 min read How To Rebase a Local Branch Onto a Remote Master in Git? Git, a powerful version control system, offers various methods to manage branches and integrate changes. Rebasing is one such technique used to incorporate changes from one branch onto another, creating a linear history. This article will walk you through the process of rebasing a local branch onto a remote master in Git. Steps To Rebase a Local Br 3 min read How to Push a Local Branch to a Remote Repository in Git? Git is a popular version control system that allows you to track changes in the codebase and collaborate with others. One of the common tasks in Git is pushing a local branch to a remote repository. This article will guide you through the steps to achieve this. Pushing Local BranchPushing a local branch to a remote repository involves creating a br 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 using Git commands locally on your machine. When to 3 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 to delete a Git branch because it will lead to a b 1 min read How Delete a Git Branch Locally and Remotely? In Git, branches are an important part of the workflow, allowing developers to work on different features, bug fixes etc. without affecting the main codebase. However, once a branch has served its purpose, it is a good practice to delete it to keep the repository clean and organized. This article will guide you through the steps to delete a Git bra 4 min read Difference Between Git remote prune, Git prune and Git fetch --prune Git is a version control system that helps developers manage and track changes in their codebase. Among its many commands, git remote prune, git prune, and git fetch --prune are essential for maintaining a clean and organized repository. This article will explain the differences between these commands, their syntax, uses, and provide examples to il 4 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 created in all git repositories. All the other bran 3 min read How to Delete Local Commit in Git? Deleting a local commit in Git can be done in a few ways, depending on whether the commit is the most recent one or if it is further back in the commit history. Here’s an article on how to delete a local commit in Git, tailored to whether you want to keep the changes made in the commit or discard them entirely: Table of Content Keeping the Changes 3 min read How To Show All Remote And Local Branch Names? Git is a powerful version control system that helps developers manage and track changes in their projects. Understanding how to list both remote and local branches is important for effective Git usage, especially when collaborating with a team. This article will guide you through the steps to display all remote and local branch names in Git. Table 3 min read Introduction to Git Branch Branching means diverging from the mainline and continue to work separately without messing with the mainline. Nearly every VCS has some form of branch support. In Git, a branch is simply a reference to the commit, where the following commits will be attached. Git vs SVN: In recent years, the use of git has risen tremendously. Unlike SVN, git allow 3 min read How to Push Git Branch to Remote? Git is the most popular version control system which records the changes made to our project over time in a special database called a repository. We can look at our project and see who has made what changes when and why and if we screw something up we can easily revert our project back to an earlier state. In this article, we will see the essential 6 min read How to Create a New Branch in Git and Push the Code? Branching in Git is a helpful feature for software developers working on a big team project. It allows the team members to work on different aspects of the software by creating a branch from the main branch. The main branch is not affected by the changes in the created branch until it is merged into the main branch. Once, work is complete for the b 8 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 through the various approaches and commands to check bra 2 min read How to Rename Branch in Git? Renaming branches in Git is important for keeping your repository organized and understandable, especially when collaborating with others. Clear and descriptive branch names improve project management and help team members identify the purpose of each branch. Renaming branches also ensures consistency and clarity throughout the development process. 1 min read How to Checkout Remote Branch in Git? When collaborating on projects using Git, you'll often need to switch between different versions of the codebase stored in remote repositories. These versions are managed through branches. To work on a specific version (branch) hosted remotely ( on GitHub), you need to check it out in your local Git repository. Table of Content Approach 1: Detachin 3 min read How to Create a New Branch in Git? Git is a powerful and widely used version control system that helps developers manage code changes across projects efficiently. One of the fundamental features of Git is branching, which allows developers to diverge from the main line of development and work on different tasks or features independently. This guide will walk you through the process 4 min read How to Change Branch Name in Git? Git is a powerful version control system widely used for managing code changes in software projects. One common task that developers encounter is renaming branches. Whether due to a change in project scope, a shift in naming conventions, or a simple typo, knowing how to rename branches efficiently is an essential Git skill. This guide will walk you 3 min read How to Set Upstream Branch on Git? It is important to Setup an Upstream Branch in Git to make the workflow smooth and manage branches efficiently. When you want to clone a new repository or work with various feature branches, you need to know how to work with upstream branches and how you can set them up. In this article, we will explore how to set up upstream branches and also see 4 min read How to Merge a Git Branch into Master? If you're working with Git, merging branches is a fundamental task. Whether you're adding new features, fixing bugs, or improving documentation, merging ensures that your changes are integrated into the main codebase. In this guide, we'll walk you through the process of merging a Git branch into the master, which helps your codebase remain up-to-da 3 min read How to Change Git Default Branch From Master? Changing the default branch in Git from master to main has become a common practice in many development teams. This shift is part of a broader movement towards more inclusive and descriptive terminology in software development. This article will guide you through the steps required to change your default branch from master to main, covering both lo 4 min read How to Reset a Git Branch to a Remote Repository? Resetting a Git branch to match a remote repository is a common task, particularly when you want to discard local changes and make your branch identical to the remote counterpart. This can be useful in scenarios where your local branch has diverged from the remote, and you want to synchronize it with the remote repository. Steps to Reset a Git Bran 3 min readArticle Tags :
- Git
- Web Technologies
Trending in News
View More- How to Delete Discord Servers: Step by Step Guide
- Google increases YouTube Premium price in India: Check our the latest plans
- California Lawmakers Pass Bill to Limit AI Replicas
- Best 10 IPTV Service Providers in Germany
- Content Improvement League 2024: From Good To A Great Article
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
-
- Data Structures & Algorithms
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, check: true }), success:function(result) { jQuery.ajax({ url: writeApiUrl + 'suggestions/auth/' + `${post_id}/`, type: "GET", dataType: 'json', xhrFields: { withCredentials: true }, success: function (result) { $('.spinner-loading-overlay:eq(0)').remove(); var commentArray = result; if(commentArray === null || commentArray.length === 0) { // when no reason is availaible then user will redirected directly make the improvment. // call to api create-improvement-post $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); return; } var improvement_reason_html = ""; for(var comment of commentArray) { // loop creating improvement reason list markup var comment_id = comment['id']; var comment_text = comment['suggestion']; improvement_reason_html += `
${comment_text}
`; } $('.improvement-reasons_wrapper').html(improvement_reason_html); $('.improvement-bottom-btn').html("Create Improvement"); $('.improve-modal--improvement').hide(); $('.improvement-reason-modal').show(); }, error: function(e){ $('.spinner-loading-overlay:eq(0)').remove(); // stop loader when ajax failed; }, }); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ $('.improvement-reason-modal').hide(); } $('.improve-modal--improvement').show(); }); function loadScript(src, callback) { var script = document.createElement('script'); script.src = src; script.onload = callback; document.head.appendChild(script); } function suggestionCall() { var suggest_val = $.trim($("#suggestion-section-textarea").val()); var array_String= suggest_val.split(" ") var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(suggest_val.length <= 2000){ var payload = { "gfg_post_id" : `${post_id}`, "suggestion" : `
${suggest_val}
`, } if(!loginData || !loginData.isLoggedIn) // User is not logged in payload["g-recaptcha-token"] = gCaptchaToken jQuery.ajax({ type:'post', url: "https://apiwrite.geeksforgeeks.org/suggestions/auth/create/", xhrFields: { withCredentials: true }, crossDomain: true, contentType:'application/json', data: JSON.stringify(payload), success:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-section-textarea').val(""); jQuery('.suggest-bottom-btn').css("display","none"); // Update the modal content const modalSection = document.querySelector('.suggestion-modal-section'); modalSection.innerHTML = `
Thank You!
Your suggestions are valuable to us.
You can now also contribute to the GeeksforGeeks community by creating improvement and help your fellow geeks.
`; }, error:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Something went wrong."); jQuery('#suggestion-modal-alert').show(); error_msg = true; } }); } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Minimum 5 Words and Maximum Character limit is 2000."); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Enter atleast four words !"); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } if(error_msg){ setTimeout(() => { jQuery('#suggestion-section-textarea').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // load the captcha script and set the token loadScript('https://www.google.com/recaptcha/api.js?render=6LdMFNUZAAAAAIuRtzg0piOT-qXCbDF-iQiUi9KY', function() { setGoogleRecaptcha(); }); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.improvement-reason-modal').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); });