2

I have a git repository with multiple branches at the origin. Some of these branches are private (individual) branches that were accidentally pushed to the remote. I do not have the ability to delete the branches on the remote. i.e. - cannot run git branch -d/-D <branch_name>.

This git repository, now, needs to be migrated to a new repository but without the private and feature branches.

Is my only option to do the following ?

  • Create a new empty repository (R1) and clone the repository locally.
  • Clone old repository (R1') inside R1.
  • git checkout <feature_branch>
  • git branch -d <feature_branch>
  • git push origin --delete <feature_branch>.

Or is there a better and smarter way of doing this ? I have about 20 of these feature and private/individual branches that I need to get rid of.

user2611581
  • 166
  • 2
  • 15
  • *I do not have the ability to delete the branches on the remote* That's quite unusual: normally if you can *create* a new branch on the remote, you can *delete* one as well, using `git push --delete ...` or `git push :`. – torek Oct 09 '17 at 18:00
  • I agree that it is unusual. Hence, I am forced to create a new repository - sans the existing branches. (Not really useful but in case it is helpful, I am trying to migrating the repo from gitolite to gitlab.) – user2611581 Oct 09 '17 at 18:04
  • Ah, Gitolite has all kinds of branch controls, yes. That explains the "how"; you'd have to have access to the control knobs (which is something you do through `git push` if the admin has allowed you such access) to re-set them to allow you to delete the branches. Anyway, there may (or may not) be a better way... – torek Oct 09 '17 at 18:09

1 Answers1

2

I am trying to migrating the repo from gitolite to gitlab

On the GitLab side, you can create an empty new repo.

On the Gitolite side, you can clone your repo locally, delete the branches, then change its remote, and push back to GitLab

cd /path/to/local/repo

git branch -rd origin/a_private_branch1
...
git branch -rd origin/a_private_branchn

Create a local branch for each remaining remote branches.

Then:

git remote set-url origin /url/to/new/gitlab/repo
git push --mirror
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250