Skip to content

Instantly share code, notes, and snippets.

@tullo
Forked from adeluccar/gist:d105299f2d5af55e3e96f9b989e7eb48
Last active December 9, 2018 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tullo/a7dcae5235299a74c0e14cfb57ccbf92 to your computer and use it in GitHub Desktop.
Save tullo/a7dcae5235299a74c0e14cfb57ccbf92 to your computer and use it in GitHub Desktop.
How to Flatten the History of a Git Repository Safely
git checkout --orphan future-master
git add -A  # Add all files and commit them
git commit
git branch -D master  # Deletes the master branch
git branch -m master  # Rename the current branch to master
git push -f origin master  # Force push master branch to github
git gc --aggressive --prune=all     # remove the old files

Works well with git submodules too. From: https://stackoverflow.com/a/13102849/1253966

@tullo
Copy link
Author

tullo commented Dec 9, 2018

@tullo
Copy link
Author

tullo commented Dec 9, 2018

Remove git tags or branches local & remote
git tag -d v0.0.2 # deletes the tag
git push origin :v0.0.2 # deletes tag on remote server

Remove branch already merged into master
git branch -d fix4321 # deletes the branch
git push origin :fix4321 # deletes branch on remote server

@tullo
Copy link
Author

tullo commented Dec 9, 2018

How do you delete a git tag that has already been pushed? https://stackoverflow.com/questions/5480258/how-to-delete-a-git-remote-tag

git push --delete origin YOUR_TAG_NAME

Delete all local tags and get the list of remote tags:

git tag -l | xargs git tag -d
git fetch --tags

Remove all remote tags
git tag -l | xargs -n 1 git push --delete origin

Clean up local tags
git tag -l | xargs git tag -d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment