troubleshooting Question

Remove all Git Commits in each branch keeping most recent code

Avatar of phoffric
phoffric asked on
Programming Languages-OtherProgrammingGit* Bitbucket
72 Comments1 Solution144 ViewsLast Modified:
In Bitbucket, we have master branch, and four developer branches, named A, B, C, D. Each branch has 10-100 commits in them. I want to keep the latest code in the respective branches, and start fresh without changing the Bitbucket URL. I would like to remove all the commits from A, B, C, D but leave the lastest code except for one commit in each one.

Here is one way I thought of (and have not tested this idea yet since I am hoping there is a better way).
  1. I git clone the repo 5 times in different local repos.
  2. In each of the 5 clones:
    1. I checkout a different branch - one of the 5 original branches.
    2. I delete the .git folder.
    3. I go a git init. (Now I think the master has the latest code in the respective branch.)
    4. I set origin to the Bitbucket URL
    5. I create and checkout the respective branch and do a git push to get the branch pushed to Bitbucket.
  3. I delete the 5 clones.
  4. I do a git clone to get the latest Bitbucket repo that now has only one commit per branch (I think).
At this point, if any developer looks at Bitbucket in their respective branch, then I hope they would see exactly what they had in there before I completed the above steps (but without history or their commits).

Is there a way to accomplish this goal without having to do a clone 6 times?
Actually, I would rather have nothing in the master branch. I will need to work with the developers to have a common folder tree structure, and then start merging.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 72 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 72 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros