git

Resources

Learning git

git checkout

Setup upstream and merge with fork/main

When you make a fork, you might want to track and merge commits from the upstream repo into your fork's main branch. To do so:

  # add the upstream/main as remote upstream
  git add remote upstream git@the_repo

  # fetch upstream
  git fetch upstream

  # merge upstream into main
  git merge upstream/main

  # resolve conflicts
  # then push to your own origin/main
  git push origin main

Rebase and squash

If you are using a forked repo, don't forget to update to latest upstream

  # After updating your main branch
  # use the interactive rebase command
  git rebase -i main

This opens a todo file for the rebase in progress, in your EDITOR. You then have to pick the first commit into which you want to squash the other commits.

  add af32ff1b12a1096f #your commit message
  add 88d6c9bb26ffb381 #your second commit message
  # ...

The file usually has instructions at the bottom on keywords and the associated action.

You can pick the commit into which you will squash the other commits.

  pick af32ff1b12a1096f #your commit message
  squash 88d6c9bb26ffb381 #your second commit message
  # ...

Commit messages are then added in order, and can be interactively

Commits can be renamed with edit or after the rebase has been finishe, with:

  git commit --amend
↑ Back to the top