I have a local git repo, one remote repo.
I made 5 commits to local repo since last pull from remote.
Now I need to push to remote. And I need to squash my last 5 commits.
I can do it by git rebase -i HEAD~5
But it’s not good. I don’t want to change anything in my local repo. I want to push one squashed commit to remote and leave 5 unchanged commits in my local repo.
Any ideas?
UPD:
what about if I have my local repo with 5 commits. and I need to create new remote repo to share my code with others. How to squash commits for this new repo?
Slight variation from Titas‘s answer, without touching your
masterbranch, and squashing on a new branch (that you would push to your new repo)But that would push the full history of master, +1 (squashed) commit, on your new repo.
If you wanted a branch new history, with your repo as after the 5 new commits, it is easier to:
.gitin that local clone,git init.(ie, re-create a new local git repo from all the existing files),