References:

Let’s start from an repo on gitHub, for example Hugo Docs

First, let’s fork it on GitHub on personal account

Fork on GitHub

Then git clone the forked repository. This would automatically create the associated repo as a origin remote (visible with git remote -v)

Add the original repo as upstream remote with git remote add upstream git_repo_url. This would allow to rebase before pushing.

Create a feature branch with git checkout -b feature-branch (-b puts you automatically on the newly created branch).

Work on the change, git add and git commit.

Once ready to make the Pull Request, time for rebase:

  • First squash the commits to only have one (with git rebase -i hash-of-commit-before-the-first-one-to-squash)
  • Then rebase from upstream:
    • git checkout master
    • git fetch upstream
    • git merge upstream/master
    • git checkout feature-branch
    • git rebase master(his is also possible to ONLY rebase the feature branch but better to do it from master)
  • Finally, push our remote branch and do the Pull Request on GitHub
    • git push origin feature-branch
    • and create the PR

If we need to update the PR:

  • Use the same approach than above (especially squash the commits) and at the end, “force push” to the remote branch with git push -f origin feature-branch