Skip to content

Instantly share code, notes, and snippets.

@stvhwrd
Last active April 3, 2020 19:10
Show Gist options
  • Save stvhwrd/88f5cbd87e30edfd8480d430208732e6 to your computer and use it in GitHub Desktop.
Save stvhwrd/88f5cbd87e30edfd8480d430208732e6 to your computer and use it in GitHub Desktop.
Local steps for a nice clean squashed git commit.

Squashing git commits into one atomic commit

See Git-Branching-Rebasing for the built-in way. Here's how to do it manually:


Preconditions: On a new branch, forked off of develop and now ready to merge back into develop.

  1. Fetch updates from remote

    git fetch origin develop

  2. Ensure that current branch is the one I intend it to be

    git checkout my-feature-branch-name

  3. Create a backup branch in case all goes wrong

    git branch backup-of-my-feature-branch-name

  4. Merge develop branch into my branch

    git merge origin/develop

  5. Deal with any merge conflicts, save the affected files

  6. Soft reset to unstage all modified files

    git reset origin/develop

  7. Add the files that I want included in this commit

    git add --all or git add file1 file2

  8. One single commit message that will represent the entire group of changes

    git commit -m "one single message"

  9. Push the changes to my remote fork. Use --force flag if commits have been pushed to this remote branch since branching off of develop. The syntax here is <server> <local branch>:<remote branch on server>

    git push --force origin my-feature-branch-name:my-feature-branch-name

  10. Create a pull request on repository server (GitHub, VSTS, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment