On Thu, 28 Jul 2016 09:37:00 -0700 (PDT)
Valencia <divinecreationsvo...@gmail.com> wrote:

> I have 2 branches in my repo. I am done with most of the code
> changes. Therefore, I want keep just one branch on my repo. How do I
> completely remove a remote branch. 
> 
> I read online that we can use "git branch -d <branch-name>, to delete
> branches, however, the git history remains intact. But I need to
> clear the history also. 
> 
> If anyone could help me with this issue then it would be great.

Well, I'm pretty sure this is covered in any Git book, so I'd really
advise you to read one.

Git has somewhat geeky approach to removing "refs" (heads (branches)
and tags) in remote repositories: you have to "push nothing" to a ref
to delete it.
To explain, consider how you push.

To begin with, the command

  $ git push origin foo:bar

would first resolve the local name "bar", then resolve the name "bar"
in the remote repository known as "origin" and then try to update
whatever is named "bar" in that repository with the history reachable
from whatever is named "foo" in our local repository.
The rules of resolving ref names are covered in the "gitrevisions"
manual page (run `git help revisions` read it).

Now you could be more specific.  Say, to push a branch (head) "foo" to a
tag "bar", you'd call:

  $ git push origin refs/heads/foo:refs/tags/bar

This is needed if there is any confusion of the resolution of a
particular ref.

The whole "foo:bar" or "refs/heads/foo:refs/tags/bar" thing is called
"the refspec" in Git's parlance, which stems from "ref specification".

OK, so you want to "push nothing" to a remote ref to delete it.
To do that, you just omit the lef-hand side of the respec, so

  $ git push origin :bar

would try to delete whatever ref the name "bar" refers in the remote
repository.  If you want to be specific, do

  $ git push origin :refs/heads/bar

to delete a branch; to delete a tag, you'd use "refs/tags/<tagname>".

The last bit is that if your remote repository is "known" to the local
one (as "origin" is in many cases), you'd also want to delete the so
called "remote branches" of this repository which are stored locally
(those "origin/whatever" things).  To do this, either use

  $ git branch -d -r origin/<remote_branch>

(notice the "-r" command-line option) or run

  $ git remote prune origin

which asks the named remote "origin" about what branches it has and
deletes all the locally stored remote branches for that repository which
were tracking branches no longer present in it.

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to