GitHub

Prerequisites: Intro to Git

Setup

Create an account on GitHub.

Create SSH key pair

ssh-keygen -t rsa -b 4096 -C "your_email@youremail.com"

See this for more.

Add public key to GitHub

cat ~/.ssh/id_rsa.pub

Copy the entire block, then follow the instructions here to add it to your account.

Usage

To push an updated commit, it's best to use this command to not overwrite a teammates commit. If you cannot push by running this command then update your local repo by pulling and rebasing, then run this command again.

git push --force-with-lease

New patchset

Make sure new patchsets are created with git commit. Using git commit --amend will change a commit already merged upstream and lead to conflicts. Commit messages should have a format like this:

Implement a thing

Optional extended description that should be complete sentences.

Fixes #42.

where 42 would be the issue number being closed by this PR. The last line ensures the issue is automatically closed when the PR is merged. Make sure each issue resolution is a separate branch and PR.

Revisions to patchset

Any changes should be incorporated into the commit previously pushed by either amending or rebasing (not pushing a new commit on top of the old one). Gerrit tracks the revisions using the "Change-Id" line at the bottom of the commit message. Make sure this line does not change and remains the last line during commit message modifications. Otherwise, a new patchset will be created instead.

Verify this was done correctly by inspecting the output of git log main..HEAD. There should be only one commit listed and its Change-Id should match the old one.

Uncommitted changes

git commit --amend

Squashing committed changes

If a new commit or commits were made while working, they should be squashed into the first before submitting it all as a new revision. To do so, run

git rebase -i <commit hash before your commits>

The first commit in the resulting generated file should be set to "r" for "reword" if the commit message needs to be altered to include parts of the other two commits. The other commits should be set to "f" for "fixup" so their contents are squashed into the first commit. git rebase descriptions for other options are in the file comment.

Git (advanced usage) lecture notes

Versioning

Messing with history

Nuclear option for binary files

Useful Git features