As you know that, Branching and merging are essential concepts in Git, enabling efficient collaboration, experimentation, and version control in software development. Today, we will discuss, how to remove git branch from local and remote. Lets start discussion.
In Git, a branch is a separate line of development in a repository. It's a way to work on new features, bug fixes, or experiments without affecting the main code-base (usually called the "master" branch). Branches allow multiple developers to work on different aspects of a project simultaneously, making it easier to manage and merge changes later.
How to Remove Git Branch
To remove a Git branch, you can follow these steps depending on whether the branch is local or remote:How to Remove Git Branch From Local
git branch -d branch_name
The -d flag will delete the branch only if it has been fully merged. If the branch has not been fully merged, Git will prevent the deletion to avoid potential data loss.
git branch -D branch_name
The -D flag (uppercase) force deletes the branch even if it has not been merged.
How to Remove Git Branch From Remote
git push origin --delete branch_name
This above command tells Git to delete the branch from the remote repository. Replace origin with the name of the remote if it’s different.
You can also use alternative command as following below.
git fetch origin
git branch -r -d origin/
