Skip to content
dozens edited this page Oct 3, 2024 · 14 revisions

History is written by those with advanced git skills

-https://twitter.com/elijahmanor/status/773194706830368769

Get good at git: https://xkcd.com/1597/

shortcuts

I use the shortcuts provided by the oh-my-zsh git plugin.

commit messages

Don't be this guy: https://xkcd.com/1296/

Use emoji

Use good formatting

Be Conventional!

Pre-commit checklist:

  • Only related/necessary changes/files are included.
  • Unrelated/unnecessary changes/files are removed.
  • There are no typos. (Run a spell checker.)
  • All comments are still up to date.
  • Remove all console logs/debugging code.
  • Double check that all requirements are met.
  • All tests are passing.
  • There are no linter errors.
  • All edge cases are covered.
  • Have I verified that the code meets the requirements?

situations and use-cases

Often and not-often used git commands.

interactive add

use: approve/stage each hunk. This will prevent acidentally committing console.logs, etc.

  • ga -i for interactive staging/patching.
  • ga -p to drop straight into patch mode.

interactive rebase

use: squash, reorder, and edit commits. general rewriting of time

to change last N commits:

git rebase -i HEAD~N

made changes to the wrong branch

Haven't committed yet:

  1. git stash - stash your changes
  2. gco -b feature/branch - branch off of the current branch
  3. git stash pop - pop your changes off the stack into the current branch

Have committed:

  1. git branch feature/branch - branch off the current branch
  2. git reset --hard HEAD^ - undo the last commit
  3. gco feature/branch

Edit the last commit msg

gc --amend

Added wrong files to last commit

  1. git reset --soft HEAD~1
  2. look at gd --staged and git reset the files you did not want to include in your commit.
  3. gc -c ORIG_HEAD will commit with the original commit message.
  4. You now have uncommited changes to either include in the next commit, or to discard with gco <file>.

Move a commit to another branch

e.g., committed to development, meant to commit to feature/xyz.

  1. Get the sha of the commit from git log on development.
  2. gco feature/xyz and git cherry-pick <sha>. You may have to resolve conflicts here.
  3. gco development and git reset --hard HEAD^
  4. Finally, gco feature/xyz and continue working.

Excluding local files

Sometimes I want to keep a notes file in a project, but I don't want to commit that file to the .gitignore or anything.

echo "notes" >> ./.git/info/exclude

Resources:

git send-email

The Fork + Pull Request model was pioneered by GitHub, and copied by other git hosts, to keep you in the browser.

Git was originally designed to be used by email patches and, optionally, using a listserv.

See:

Hooks

A tiny CI system using the post-recieve git-hook

=> https://www.0chris.com/tiny-ci-system.html

Branching Strategies

Multiple Identities

Notes

Stacked Diffs Versus Pull Requests

The basic idea of stacked diffs is that you have a local checkout of the repository which you can mangle to your heart’s content. The only thing that the world needs to care about is what you want to push out for review. This means you decide what view of your local checkout the reviewers see. You present something that can be ‘landed’ on top of master.

https://jg.gg/2018/09/29/stacked-diffs-versus-pull-requests/

Patch-Request Workflow

An alternative to the ubiquitous githubesque pull request, and also to the git send-email methods of git collaboration.

https://pr.pico.sh/

Alternatives

Clone this wiki locally