Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Best way to restart repo?

We have a repo we've been playing with but want to reset it; is it better to clear the history somehow or just delete the branch and recreate it? I'm afraid that recreating it will be buggy in BitBucket.

1 answer

You can use 

git reset --hard <commit_id>

to reset the branch pointer to the specified commit and also reset the working directory.  If the old commits had been pushed to your remote, you will have to do a force push to push the reset versions.

git push -f

It is possible that your remote may be configured to reject force pushes.

You will lose all the code changes in commits that you've reset, so be sure.  If you wanted to retain your ability to access them just in case, you could create a separate branch to point to them before reseting.  

Deleting a branch and recreating it is also valid - a branch is just a pointer to a commit, so this will have exactly the same effect with all the same possible concerns.

The initial commit was from another repo that I had imported, and I needed to just reset the repo without the old history without recreating it in BitBucket, so I init'd a new repo in another folder, copied .git to the folder, deleted all the files but the .gitignore, made an initial commit (before setting the remote), then added the remote and force-pushed, and it worked, though it some minutes for BitBucket to completely recognize it.

sorry, I think I misunderstood your question.  Yeah, if you want to keep the contents of the repo as it currently is but wipe away its history (for whatever reason), that procedure sounds about right.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in DevOps

Step up your DevOps game webinar Q&A series - Questions answered!

  On October 21st, 2020 we hosted a webinar titled,   Step Up You DevOps Game with 4 Key Integrations for Jira and Bitbucket. We had a great showing and high engagement, but that meant th...

101 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you