I want to add a feature to a git repository. Have already created a few commits in my local branch named Feature-branch In order to push this branch to my remote repository as a single commit follow these simple steps:

  1. Pull latest code from remote master branch: git pull --rebase origin master

  2. Switch branch: git checkout Feature-branch

  3. Squash your commits to one: git rebase -i master

    • Running this command gives you a list of commits in your text editor that looks something like this:

    • Replace pick with squash to convert the corresponding commits to one single commit:

    • After you save and exit the editor, Git applies all changes and then puts you back into the editor to merge all the commit messages:

    • Change the commit message and save and close the editor to create one single commit:

    • Commits are squashed to one:

  4. Force push your feature branch: git push origin Feature-branch -f

There! your feature is pushed to a new branch as a single commit :)