git delete branch

0 votes

How do I delete a Git branch locally and remotely? In order to delete the branch both, locally and remotely, what must I do?

Here is the Unsuccessful Attempt to Remotely delete the branch

$ git branch -d remotes/origin/bugfix 
error: branch 'remotes/origin/bugfix' not found. 
$ git branch -d origin/bugfix 
error: branch 'origin/bugfix' not found. 
$ git branch -rd origin/bugfix 
Deleted remote branch origin/bugfix (was 2a14ef7). 
$ git push 
Everything up-to-date 
$ git pull 
From github.com:gituser/gitproject 
* [new branch] bugfix -> origin/bugfix 
Already up-to-date.

Both, locally and remotely, what and how should I do differently in order to delete the remotes/origin/bugfix branch?

Feb 8 in Others by Rahul
• 8,980 points
16 views

1 answer to this question.

0 votes
The following change in the code given below can answer your question:-

$ git push -d <remote_name> <branchname> 
$ git branch -d <branchname>

However, one must keep in mind that the <remote_name> will be the origin, in most of the cases. 


To eliminate from the local branch, the following code can be used:-
 

$ git branch -d <branch_name> 
$ git branch -D <branch_name>

The -d option is another word or substitute for --delete, which only deletes the branch if it has already been fully integrated into its upstream branch.
The -D option is another word or substitute for --delete --force, which deletes the branch regardless of its merged status on the system. 

According to the Git v2.3 version, the git branch -d (delete) learned to honor the -f (force) flag. An error will occur once a user tries to delete the selected branch.
However, according to the Git v1.7.0 version, you can delete a remote branch using

$ git push <remote_name> --delete <branch_name>

which might be easier to memorize than
 

$ git push <remote_name> :<branch_name>

This was added in Git v1.5.0  "to delete a remote branch or a tag."

In Git v2.8.0, one can also use git push with the -d option as an alias for --delete. Therefore, the version of Git you have installed will decide whether you need to use the easier or harder syntax, respectively. 

answered Feb 8 by Soham
• 8,730 points

Related Questions In Others

0 votes
1 answer

How do I check out a remote Git branch?

The answer to your question has been ...READ MORE

answered Feb 10 in Others by Rahul
• 8,980 points
31 views
0 votes
0 answers

Webinar Recording on GIT

Hi Team, I was not able to attend ...READ MORE

Jul 12, 2020 in Others by Sudhakar
• 120 points
157 views
0 votes
1 answer

'git rev-parse HEAD' is not recognized as an internal or external command

Hi@akhtar, I also faced the same problem. You ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,360 points
1,712 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,665 views
+2 votes
1 answer
0 votes
1 answer

git revert last commit

To answer your question, you can try ...READ MORE

answered Feb 8 in Others by Soham
• 8,730 points
36 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP