Clean history

Without submodules

  • cd repo
  • rm -rf .git
  • git init -b master
  • git add .
  • git commit -m "Initial commit"
  • git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPO>.git
  • git push -u --force origin master

With submodules

  • git checkout --orphan newBranch
  • git add -A add all files and commit them
  • git commit
  • git branch -D master delete the master branch
  • git branch -m master rename the current branch to master
  • git push -f origin master force push master branch
  • git gc --aggressive --prune=all remove the old files

Untrack files already added to git repository based on .gitignore

  • commit and push all
  • git rm -r --cached .
    • rm is the remove command
    • -r will allow recursive removal
    • –cached will only remove files from the index. Your files will still be there.
    • The . indicates that all files will be untracked. You can untrack a specific file with git rm --cached foo.txt
  • git commit -m ".gitignore fix"
  • push

Everything about .gitignore

https://www.atlassian.com/git/tutorials/saving-changes/gitignore

Remove unpushed commit

Delete the most recent commit:

git reset --hard HEAD~1

Delete the most recent commit, without destroying the work you’ve done:

git reset --soft HEAD~1