How to combine multiple commits (in a local repository) into a single one and push it to public repository

When you work on a team project, you don’t want to push multiple small commits in your local machine to the public shared one (cause your small commits maybe only relevant to the local repo.) What you want is a single major commit (summary of what you have done) so that you will not overflow the public commit history. For example, you have 1000 local commits to finish a task (let’s say you make a plus function in a calculator app <– oh well, this is impossible, but let’s assume this is the case), and you don’t want other to see ALL 100 commits, but simply a summary of what you have done, i.e., “Implement plus function”. Here it’s the step.

a. git branch xxx

(open a new branch)

b. git checkout xxx

(switch branch from master to xxx)

c. do whatever changes you have and keep committing. Once you believe you finish a major change and want to push to origin master, do next step

d. git checkout master

(check out master branch first)

e. git merge –squash master xxx


f. git commit

(edit the commit content, remove all the current one. Type in new content and save and exit. NOTE: do not need to remove anything beyond #)

g. git pull origin master

(pull before commit)

h. git push origin master

(push it out)

DONE (can create a new branch and repeat the process again)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s