This is a separate answer, partly so that I can get some formatting in, and also because we seem to be talking about a different repository and/or branch at this point.
Copying from GitHub, so I can see what's actually there
I start by cloning git://github.com/weidai11/cryptopp
:
$ cd tmp
$ git clone git://github.com/weidai11/cryptopp
Cloning into '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 I can view the branches as seen on GitHub. In my own repository, I have only a local master
(just now created by 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 that there is a branch named alignas
. Let's find the commit to which it points:
$ git rev-parse origin/alignas
d0760a44eab5e6da04690d4a0d80fc306abd0844
Are there any other names that point to this commit? If the branch is fully merged into some other branch, there will be, if not there will not:
$ git branch -r --contains d0760a44eab5e6da04690d4a0d80fc306abd0844
origin/alignas
So there is at least one commit on origin/alignas
that is not on any other branch. A brief look at it shows (edited a bit):
$ git show --name-status origin/alignas
commit d0760a44eab5e6da04690d4a0d80fc306abd0844
Author: [redacted]
Date: [redacted]
Fix CRYPTOPP_ALIGN_DATA placement
M rijndael.cpp
If I were to delete this branch from GitHub now—not that I could, I have no write permission on GitHub for this repository and git://
offers no write permission—that commit would be dropped from GitHub, perhaps with some others. (Further inspection shows that commits before this point are mostly merges of things that are on other branches; we'd lose the merge commits, but the things being merged-in are protected by those other branches.)
Deleting from GitHub (I can't, so, hypothetical only)
Should you wish to delete this branch from GitHub right now, even though there is at least one commit that this would lose, you1 could do this:
git push --delete origin alignas
That would leave you with remote-tracking branch origin/alignas
in your own repository (assuming you have it now), but git fetch origin --prune
or git remote prune origin
would subsequently delete origin/alignas
from your own repository:
git fetch origin --prune
or:
git remote origin prune
The git fetch origin --prune
step should do the job, but in at least some versions of Git, this was broken for a while.
1Assuming you have write permission and are using https://
or ssh://
, of course. Neither is true for me, so I cannot.
The local branch, in your repository
You might also have local branch alignas
in your repository. I do not have it in mine yet, but before you delete alignas
from GitHub, while I still have origin/alignas
in my repository, I can now do this:
$ git checkout alignas
Branch alignas set up to track remote branch alignas from origin.
Switched to a new branch 'alignas'
and now I do have that branch:
$ git branch -l
* alignas
master
It's my current branch. Let's say I want to delete it from my repository copy (while leaving origin/alignas
alone):
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
(this step is necessary because Git won't let me delete the branch I'm standing on)
$ git branch -d alignas
warning: deleting branch 'alignas' that has been merged to
'refs/remotes/origin/alignas', but not yet merged to HEAD.
Deleted branch alignas (was d0760a4).
My version of git is 2.8.1. Apple git 1.8.x will probably give you an error about the branch not being properly merged.
Let me create local alignas
again, then delete it again, more forcefully this time:
$ git checkout alignas
Branch alignas set up to track remote branch alignas from origin.
Switched to a new branch 'alignas'
This is the same as before: my Git used remote-tracking branch origin/alignas
to create local branch alignas
, and then put me on that branch.
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
$ git branch -D alignas
Deleted branch alignas (was d0760a4).
Again, I have to get off it, then I can delete it. Once I have deleted it locally, I can't accidentally push it (see below).
Everyone else
Anyone else who has a copy of this repository may also have an alignas
branch. Suppose Fred has a copy, for instance, and he does not delete his alignas
. Suppose further that he has write permission for this repository on GitHub.
Any time after you have deleted alignas
from GitHub, Fred could re-create it. All he has to do is git push origin alignas
or git push origin --all
, and it comes back on GitHub.
To stop that, you must stop Fred. :-)