← Programming

Git

Forking workflow

Setup

  1. Fork the official repository
  2. Clone my fork
git clone <my fork's SSH remote URL>
  1. Add the upstream
git remote add upstream <official repository's SSH remote URL>

Start new work

git checkout main
git fetch upstream
git rebase upstream/main
git push origin main
git checkout -b feature/<name>

Daily work

git add <files>
git commit -m "message"
git push origin feature/<name>

Sync with main before merging

git fetch upstream
git rebase upstream/main
git push --force-with-lease origin feature/<name>
Note

--force-with-lease is safer than --force since it refuses if someone else pushed since your last fetch.

If rebase hits a conflict

# check conflicted files:
git status

# fix the conflict in your editor, then:
git diff --check # check for leftover conflict markers
git add <resolved files>
git rebase --continue

# to bail out entirely:
git rebase --abort