Git contributions - rebase, squash, push feature branch

Major Git projects such as CMake have a contributor workflow that goes like:

  1. Fork the main repo
  2. on the fork, create a feature branch

    git checkout -b add-feature1
    1. once changes accepted:
    git checkout master
    git remote add upstream (URL of the original remote repo, not your fork)
    git fetch upstream
    git rebase upstream/master

    Now the local master branch is up to date with the remote project.

  3. update the local branch to remote master

    git checkout add-feature1
    git rebase master
    1. This step “squashes” all your commits down to one. Be sure to make a copy of your fork directory first!
    git rebase -i HEAD~10   # or however many commits you made

    change all the “pick” of your changes to “s”, EXCEPT for the first commit you made.

  4. Force push your changes to the feature branch remote.