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
    
  3. once changes accepted:
    git checkout master
       
    git remote add upstream (URL of the main repo, not your fork)
       
    git fetch upstream
       
    git rebase upstream/master
    

    Now your master branch is up to date with the main project.

  4. update your local branch to main master
    git checkout add-feature1
       
    git rebase master
    
  5. 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.

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

Categories:

Written by Michael Hirsch, Ph.D. //

Comments