Git Error rejected master -> master (non-fast-forward)

I got error from the git while committing the changes using push - u origin master

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:mahesh/childtheme.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.


I copied the files in the directory into another temp directory. And then ran the following command.

git pull --rebase

Then I tried to reset the git using.

git --reset hard origin/master

or

git clean -d -x -n

This cleared the git content on the local directory.  I pulled the git content from the github repository to see if it syncs properly.

git push

This synced the git local content with the githhub remote content. Then copied the temporary files content which i saved earlier into the local directory where i was running git. And then committed the changes.

git commit

It worked for two reasons. I cleared the git and also rebased it as well. Then the properly using the push on remote server, it synced just fine.