Skip to content

Tips

Pull all remote branches

git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all

How to delete the git history

Checkout/create orphan branch (this branch won't show in git branch command):

git checkout --orphan latest_branch

See what you need to include

git status
git add -A # if you want to add all
git commit -am "clean history"

Delete main branch

git branch -D main

Rename the current branch to main

git branch -m main

See the remotes and push changes This ensures you don't overwrite other people's work

git remote  -v
git push --force-with-lease REMOTE main

Gitlab: no allowed to force push

If your are pushing to gitlab and get this error "You are not allowed to force push code to a protected branch on this project"

Enable force push in the repository under Settings > Repository > Protected branches

See the branch and enable "Allowed to force push" and repeat the push. After the push, disable it