I have been working on a private repo for a while, and am going to release to GitHub.
The problem is i've got many many commits, and for hygiene's sake I'd like only a single commit to appear in GitHub.
How do I push without pushing history? i.e consolidate the entire MASTER into a single commit
many thanks in advance.
Doug
To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.
Usually one would use git rebase --interactive HEAD~n
where n is the no. of commits you want to merge into one. However, in your case you want to squash the entire history into a single commit and since rebasing without a parent (upto the initial commit) isn't possible we have to use git reset
and git commit --amend
.
Here's what you do:
git log --oneline
. Find the SHA of your initial commit.fe7d5d1
. Run git reset fe7d5d1
. This will reset the branch to the inital commit.git add .
to stage all your changes.git commit --amend -m "Initial commit"
.git log --oneline
.CAUTION: Never rewrite/squash/rebase commits you have already pushed to a remote repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With