How to delete the commit history in the repository:
Locally
On the remote repository
(for example, Bitbucket, GitLab, GitHub, etc.):
Recreating the repository is basically optional. If you have already reset the local history, you can simply send it to a remote repository with the -f .
git push -f origin
Attention, this cannot be done if someone other than you is using the repository! ( More on why this is and what it will be for. )
This will only replace the contents of the origin/master branch. If there are other branches on the remote repository, you can delete them as follows (separately for each branch with the name, for example, branchname ):
git push origin :branchname
Of course, if there are a lot of branches and / or tags, it will be easier to delete and re-create the entire repository.
What happened, why did the old commits
Let us analyze all executed commands in sequence.
git reset --hard
Just reset local changes.
git remote rm
It does not work without another argument, you just did not notice the error. But even if you do this:
git remote rm origin
This will only remove the entry in the local repository configuration of the connected repository (remote) under the name origin .
Farther:
git init
If this command is executed in an existing repository, then it does nothing . If you want to delete the change history and start versioning from scratch, you had to go another way: How to reset the Git history?
git remote add origin <repository_https_url_from_bitbucket>
Since the repository named origin already in the local configuration, nothing will happen.
git add README.md git add .gitignore git commit -m “init” git add . git commit -m “test tasks”
Just add a couple of commits to the local repository. If there were no changes at some step (files that did not contain changes were added / indexed), then there was no commit.
git push -u origin --all
And push the result to the origin repository. Naturally we see there all the same history of commits that we have locally. You can look at the local one, for example, like this:
git log --oneline --graph --decorate --all