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.
Here's the command to delete a branch remotely: git push <remote> --delete <branch> . The branch is now deleted remotely.
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).
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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With