Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hg-git: delete remote branch?

Is it possible to delete a remote branch with hg-git?

I can delete the tag locally (hg bm -d old-branch), but it's not obvious how to tell the git server to do the same.

like image 940
David Wolever Avatar asked Mar 20 '12 18:03

David Wolever


People also ask

What is the command to delete a branch in your remote repository?

Here's the command to delete a branch remotely: git push <remote> --delete <branch> . The branch is now deleted remotely.

How do I delete a git repository branch?

On GitHub.com, navigate to the main page of the repository. Above the list of files, click Branches. Scroll to the branch that you want to delete, then click . If you try to delete a branch that is associated with at least one open pull request, you must confirm that you intend to close the pull request(s).


2 Answers

Here's an alias for your hgrc

If you're on a Posix system, add this alias to your hgrc file:

# Example invocation:
#    hg git-delete-remote default/bad-branch
gitremotedelete = ! \
    remote=`echo $HG_ARGS | sed 's_/.*__' | sed 's_.* __'`;
    branch=`echo $HG_ARGS | sed 's_.*/__'`;
    remote_url=$($HG paths $remote | sed 's_^git+ssh://__');
    git_dir=$($HG root)/.hg/git;
    # Delete the remote branch
    git --git-dir=$git_dir push $remote_url :$branch;
    # Delete local ref to remote branch
    git --git-dir=$git_dir branch -rd $remote/$branch;
    # Delete local branch
    git --git-dir=$git_dir branch -D $branch
    echo "Don't forget to run "'`'"hg bookmark -d $branch"'`'

And invoke it like so, if you want to delete the 'default/bad-branch' remotely:

# hg gitremotedelete <name of remote>/<branch to delete>
hg gitremotedelete default/bad-branch

Doing it manually

If you want to know what the above does: here's how we'd do the same thing as an interactive session. Hopefully this is translateable to Windows.

We want to delete the Git branch on some remote. Let's find out the url of the default remote; if you need some other remote, alter as needed.

hg paths default
# git+ssh://[email protected]:some_user/some_repo.git

What is the repo root?

hg root
# /home/You/current_repo

Change to the Git directory under the repo root

cd /home/You/current_repo/.hg/git

Speak the magic words that get Git to remove a remote branch, passing the remote repo URL in the style that Git expects

git push [email protected]:some_user/some_repo.git :branch-to-delete

Also delete the remote-tracking branch, because Git does not automatically delete it. Hg-Git generates the remote-ref tags on the fly from the remote-tracking references, so deleting the remote-tracking branch in Git is necessary and sufficient to no longer see the tag in Mercurial.

git branch -rd default/branch-to-delete

Finally, delete Git's (local ref of the) local branch:

git branch -d $branch
like image 185
Esteis Avatar answered Oct 01 '22 09:10

Esteis


This was discussed on the Hg-Git mailing list on Sept. 13, 2012. The conclusion was that deleting remote Git branches is not something that Hg-Git currently supports, and the workaround is to use a separate Git client to delete the remote branch.

I've been working on improving Hg-Git's integration with bookmarks, so it's possible that this capability may be present in a future version of Hg-Git.

Related discussion: https://groups.google.com/d/topic/hg-git/Zj_-JkYsFaA/discussion

like image 44
davidmc24 Avatar answered Oct 01 '22 08:10

davidmc24