Timeline for How do I delete a Git branch locally and remotely?
Current License: CC BY-SA 4.0
45 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 2, 2025 at 6:13 | comment | added | Developer Nilesh |
Need to check the branch name first with git branch and also check git status with git status , after that make above changes accordingly. Because, we need to verify the branch and it's status.
|
|
| Dec 15, 2023 at 18:08 | history | made wiki | Post Made Community Wiki by blackgreen ♦ | ||
| Mar 24, 2022 at 3:42 | history | edited | jiasli | CC BY-SA 4.0 |
added 1 character in body
|
| Jun 1, 2021 at 3:09 | comment | added | Duncan MacIntyre | Great answer—I appreciate how the visuals explain why! You could consider making the "short answer" even shorter (e.g. list only the short versions of commands, choose one of -d and -D and note the other as per @Eric Brotto). The alternate forms can follow below. | |
| Jan 5, 2021 at 0:40 | comment | added | Gabriel Staples |
It should be noted that running git push origin --delete <branch>, as far as I can tell, ALSO deletes the locally-stored remote-tracking branch named origin/branch. So, to delete the remote branch AND locally-stored remote-tracking branch in one command, just use git push origin --delete <branch>. Then, you just need to delete the local branch with git branch -D branch. That covers the deletion of all 3 branches with only 2 commands.
|
|
| Jan 5, 2021 at 0:08 | comment | added | Gabriel Staples |
What happens if you run git fetch --prune, withOUT specifying the remote branch? Does it prune all remotes?
|
|
| Apr 11, 2020 at 11:22 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Used more standard formatting (we have italics and bold on this platform), etc.
|
| Apr 3, 2020 at 20:54 | history | edited | Gabriel Staples | CC BY-SA 4.0 |
minor change for clarity/explicitness, & spelling
|
| Apr 3, 2020 at 20:35 | comment | added | Gabriel Staples | I've read all the answers down to here and this is for sure the best answer I've read so far!--(and probably the best one on this page, period). This is especially true because it's the only answer which states this REALLY IMPORTANT fact that I never knew before: "there are 3 different branches to delete!" I had no idea! This all makes so much more sense now, and it sheds so much light on all the other answers here now too. Thanks! | |
| Apr 1, 2020 at 17:26 | history | edited | Andras Deak -- Слава Україні | CC BY-SA 4.0 |
fix markdown abuse
|
| Mar 26, 2020 at 10:37 | history | edited | Arsen Khachaturyan | CC BY-SA 4.0 |
added 51 characters in body
|
| Mar 5, 2020 at 11:21 | comment | added | David P | For the sake of future readers: What @Kermit_ice_tea is talking about above is a local branch (as described in this answer), not a remote-tracking branch. When a local branch has an "upstream branch" configured for it, it will by default pull from and push to that remote branch. A local branch that has an "upstream branch" set on it is referred to as a "tracking branch", so it's easy to confuse with remote-tracking branches due to the similar terminology. | |
| Dec 10, 2019 at 16:30 | history | edited | YakovL | CC BY-SA 4.0 |
added a short version of flag
|
| Jun 21, 2017 at 19:48 | comment | added | Kermit_ice_tea | +1 for the remote tracking branch. This branch is what causes issues when you clone someone else's branch. It keeps on tracking your commits and asking you if you want to push to that person's branch. | |
| Mar 10, 2016 at 12:20 | history | edited | Valentin Lorentz | CC BY-SA 3.0 |
HTTPS links and images
|
| Feb 23, 2016 at 7:33 | comment | added | user456814 |
@huggie that's pretty much correct. Branches in Git are just bookmarks attached to commits. So in my graphs above, there are X and origin/X bookmarks in the local clone (2 branches), and then there is X on the remote (making 3 branches).
|
|
| Feb 18, 2016 at 2:00 | comment | added | huggie | From your illustration, I can see there are local clone repo and remote origin repo. So there are at least two physical branches. Where is the third branch to delete? Is the third branch only a pointer pointing to a commit in the local clone repo? | |
| Aug 4, 2014 at 15:01 | history | edited | user456814 | CC BY-SA 3.0 |
Changed documentation anchor text and formatting, because I hated the previous formatting.
|
| Jul 31, 2014 at 6:45 | history | edited | user456814 | CC BY-SA 3.0 |
Add dash.
|
| Jul 30, 2014 at 19:13 | history | edited | user456814 | CC BY-SA 3.0 |
Updated.
|
| Jul 30, 2014 at 16:51 | history | edited | user456814 | CC BY-SA 3.0 |
Updated formatting.
|
| Jul 29, 2014 at 4:52 | history | edited | user456814 | CC BY-SA 3.0 |
Updated diagrams.
|
| Jul 29, 2014 at 4:41 | history | edited | user456814 | CC BY-SA 3.0 |
Removed more redundancy.
|
| Jul 29, 2014 at 4:32 | history | edited | user456814 | CC BY-SA 3.0 |
Removed unnecessary redundant sections, clarified answer generally, improved formatting.
|
| Jul 28, 2014 at 7:56 | history | edited | user456814 | CC BY-SA 3.0 |
Updated documentation links.
|
| Jul 21, 2014 at 17:22 | history | edited | user456814 | CC BY-SA 3.0 |
Shortened commands.
|
| Jul 21, 2014 at 15:59 | history | edited | user456814 | CC BY-SA 3.0 |
Updated branch names.
|
| Jul 21, 2014 at 15:46 | history | edited | user456814 | CC BY-SA 3.0 |
Added "short answer" section for those people who don't want to bother reading a long explanation. Also removed link to top-voted answer because I don't copy it verbatim, and the long explanation of the link detracts from the clarity of my own answer.
|
| Jul 21, 2014 at 4:05 | history | edited | user456814 | CC BY-SA 3.0 |
Updated header.
|
| Jul 10, 2014 at 18:04 | history | edited | user456814 | CC BY-SA 3.0 |
Add pictures.
|
| Jul 10, 2014 at 17:58 | history | edited | user456814 | CC BY-SA 3.0 |
Add picture.
|
| Jul 8, 2014 at 0:52 | history | edited | user456814 | CC BY-SA 3.0 |
Updated formatting, clarified.
|
| Jun 29, 2014 at 11:58 | audit | First posts | |||
| Jun 29, 2014 at 11:59 | |||||
| Jun 11, 2014 at 14:34 | history | edited | user456814 | CC BY-SA 3.0 |
Made it clearer that the alternative pruning method is only an option when the remote branch is already deleted.
|
| Jun 6, 2014 at 1:00 | history | edited | user456814 | CC BY-SA 3.0 |
Added a tl;dr summar header section.
|
| Jun 5, 2014 at 22:22 | history | edited | user456814 | CC BY-SA 3.0 |
Clarified why the original poster's original attempts to delete the remote branch didn't work.
|
| Jun 5, 2014 at 22:03 | history | edited | user456814 | CC BY-SA 3.0 |
Added warning that all obsolete remote-tracking branches are pruned, fixed typo.
|
| Jun 5, 2014 at 21:56 | history | edited | user456814 | CC BY-SA 3.0 |
Greatly clarified answer.
|
| Jun 5, 2014 at 21:32 | history | edited | user456814 | CC BY-SA 3.0 |
Use better formatting for quote.
|
| Jun 4, 2014 at 19:55 | history | edited | user456814 | CC BY-SA 3.0 |
Made answer for comprehensive by including alternative solutions.
|
| Jun 3, 2014 at 14:37 | history | edited | user456814 | CC BY-SA 3.0 |
Added version differences for deleting remote branches.
|
| Jun 2, 2014 at 13:23 | history | edited | user456814 | CC BY-SA 3.0 |
Fixed syntax highlighting.
|
| May 30, 2014 at 19:01 | history | edited | user456814 | CC BY-SA 3.0 |
Corrected header.
|
| May 30, 2014 at 18:45 | history | edited | user456814 | CC BY-SA 3.0 |
Added relevant release notes.
|
| May 30, 2014 at 18:32 | history | answered | user456814 | CC BY-SA 3.0 |