i have development branch called atomics (more correctly, atomics
). finished being developed. tested ok, merged master. i'm ready delete since no longer needed.
i really thought question clear , answered well: delete git branch both locally , remotely. alas, did not work...
here's did:
# accepted answer, succeeded $ git push origin --delete atomics # shit, did not delete local branch $ git branch -a ... * master atomics # answer. whoops, causes error git push --delete origin atomics error: unable delete 'atomics': remote ref not exist # try yet answer: git fetch --all --prune # check again $ git branch -a ... * master atomics
according torek's answer:
$ git branch -d atomics error: branch 'atomics' not merged. # see below on prelude may have caused # (yet git black-hole) # yep, did not work $ git fetch --prune origin $ git branch -a * master atomics ...
in case matters, apple's git:
$ git --version git version 1.8.5.2 (apple git-48)
at point, have 2 questions. first, how delete local , remote branches that works? may seem redundant given cited question, question not appear answered though answer accepted.
second, how recover special git state things partially deleted?
here's prelude. --squash
ensure log on master accurate.
$ git checkout master $ git merge --squash atomics # these files existed in master, 'git push' after merge # did nothing. also, 'git status' showed modified. $ git add a.h b.h a.cpp b.cpp $ git commit a.h b.h a.cpp b.cpp -m "mergae atomics master" $ git push
edit: accepted torek's answer because man worked damn hard not out of it. unfortunately, procedure did not work question; , did not work on following experiment, when dev branch deleted. tool broken, , there's no amount of q&a can fix it.
this separate answer, partly can formatting in, , because seem talking different repository and/or branch @ point.
copying github, can see what's there
i start cloning git://github.com/weidai11/cryptopp
:
$ cd tmp $ git clone git://github.com/weidai11/cryptopp cloning 'cryptopp'... remote: counting objects: 7756, done. remote: compressing objects: 100% (75/75), done. remote: total 7756 (delta 33), reused 0 (delta 0), pack-reused 7681 receiving objects: 100% (7756/7756), 7.48 mib | 1.87 mib/s, done. resolving deltas: 100% (5480/5480), done. checking connectivity... done. $ cd cryptopp/
now can view branches seen on github. in own repository, have local master
(just created git clone
).
$ git branch -a * master remotes/origin/head -> origin/master remotes/origin/alignas remotes/origin/arm-neon remotes/origin/det-sig remotes/origin/master remotes/origin/solaris
i see there branch named alignas
. let's find commit points:
$ git rev-parse origin/alignas d0760a44eab5e6da04690d4a0d80fc306abd0844
are there other names point commit? if branch merged other branch, there be, if not there not:
$ git branch -r --contains d0760a44eab5e6da04690d4a0d80fc306abd0844 origin/alignas
so there @ least 1 commit on origin/alignas
not on other branch. brief @ shows (edited bit):
$ git show --name-status origin/alignas commit d0760a44eab5e6da04690d4a0d80fc306abd0844 author: [redacted] date: [redacted] fix cryptopp_align_data placement m rijndael.cpp
if delete branch github now—not could, have no write permission on github repository , git://
offers no write permission—that commit dropped github, perhaps others. (further inspection shows commits before point merges of things are on other branches; we'd lose merge commits, things being merged-in protected other branches.)
deleting github (i can't, so, hypothetical only)
should wish delete branch github right now, though there @ least 1 commit lose, you1 this:
git push --delete origin alignas
that leave remote-tracking branch origin/alignas
in own repository (assuming have now), git fetch origin --prune
or git remote prune origin
subsequently delete origin/alignas
own repository:
git fetch origin --prune
or:
git remote origin prune
the git fetch origin --prune
step should job, in @ least versions of git, broken while.
1assuming have write permission , using https://
or ssh://
, of course. neither true me, cannot.
the local branch, in your repository
you might also have local branch alignas
in repository. not have in mine yet, before delete alignas
github, while still have origin/alignas
in my repository, can this:
$ git checkout alignas branch alignas set track remote branch alignas origin. switched new branch 'alignas'
and do have branch:
$ git branch -l * alignas master
it's current branch. let's want delete my repository copy (while leaving origin/alignas
alone):
$ git checkout master switched branch 'master' branch up-to-date 'origin/master'.
(this step necessary because git won't let me delete branch i'm standing on)
$ git branch -d alignas warning: deleting branch 'alignas' has been merged 'refs/remotes/origin/alignas', not yet merged head. deleted branch alignas (was d0760a4).
my version of git 2.8.1. apple git 1.8.x give error branch not being merged.
let me create local alignas
again, delete again, more forcefully time:
$ git checkout alignas branch alignas set track remote branch alignas origin. switched new branch 'alignas'
this same before: git used remote-tracking branch origin/alignas
create local branch alignas
, , put me on branch.
$ git checkout master switched branch 'master' branch up-to-date 'origin/master'. $ git branch -d alignas deleted branch alignas (was d0760a4).
again, have off it, can delete it. once have deleted locally, can't accidentally push (see below).
everyone else
anyone else has copy of repository may also have alignas
branch. suppose fred has copy, instance, , not delete his alignas
. suppose further has write permission repository on github.
any time after have deleted alignas
github, fred re-create it. has git push origin alignas
or git push origin --all
, , comes on github.
to stop that, must stop fred. :-)