0

So I have this huge bitbucket repository with so many branches, each with tens of commits some of which are really small. Now that the entire thing works perfectly, I want a clean repo with only the final commits and required branches. How do I achieve a 'repository clean-up' where I can remove the unnecessary branches and the commits and have a final clean repo?

Please help me out.

HalfBloodPrince7
  • 153
  • 1
  • 14
  • https://community.atlassian.com/t5/Answers-Developer-Questions/Is-there-a-way-to-delete-branches-in-bulk/qaq-p/547331 – avigil Mar 30 '18 at 06:03

2 Answers2

0

From the solution here:

# Make sure remotes are up to date (with stale remotes purged):
git fetch -p

# Initial no-op run --- do the branches to delete look correct?
# Be careful to omit 'master' from the output.
git branch --remote --merged origin/master | grep -v 'master' | cut -b 10- | xargs

# Do the bulk delete!!!  (can take a long time...)
git branch --remote --merged origin/master | grep -v 'master' | cut -b 10- | xargs git push --delete origin

This will delete branches that have been merged into a 'master' branch. You can modify to reflect whatever organization your repo is using.

avigil
  • 2,218
  • 11
  • 18
0
  1. first clone the final commit from your bitbucket repo in your pc. for this please see this post: https://coderwall.com/p/xyuoza/git-cloning-specific-commits

  2. then clean full repository without deleting repo itself. for this please see the this post: Delete all files and history from remote Git repo without deleting repo itself

  3. then again push the final copy(that copy you cloning from git repo earlier) to your desire bitbucket repository.

I'm sorry if i wrote something unapproprite here. I'm novice. So please don't mind. I don't know if you want the solution like this or not! if not then I'm sorry again.

Md. Arif
  • 448
  • 1
  • 5
  • 13
  • I have more than one branch that I want to retain, is it possible through this method? Can I clone the most recent commits of multiple branches and delete the complete repo and push them again to the respective branches so that they only have a single final commit? – HalfBloodPrince7 Mar 30 '18 at 06:20