-
Notifications
You must be signed in to change notification settings - Fork 1
git
Chrisman Brown edited this page Jul 3, 2019
·
14 revisions
Get good at git
I use the shortcuts provided by the oh-my-zsh git plugin.
Don't be this guy: https://xkcd.com/1296/
Use emoji
- https://github.com/dannyfritz/commit-message-emoji
- https://github.com/atom/atom/blob/master/CONTRIBUTING.md#git-commit-messages
Use good formatting
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?
Often and not-often used git commands.
use: approve/stage each hunk. This will prevent acidentally committing console.log
s, etc.
-
ga -i
for interactive staging/patching. -
ga -p
to drop straight into patch mode.
use: squash, reorder, and edit commits. general rewriting of time
to change last N commits:
git rebase -i HEAD~N
Haven't committed yet:
-
git stash
- stash your changes -
gco -b feature/branch
- branch off of the current branch -
git stash pop
- pop your changes off the stack into the current branch
Have committed:
-
git branch feature/branch
- branch off the current branch -
git reset --hard HEAD^
- undo the last commit gco feature/branch
gc --amend
git reset --soft HEAD~1
- look at
gd --staged
andgit reset
the files you did not want to include in your commit. -
gc -c ORIG_HEAD
will commit with the original commit message. - You now have uncommited changes to either include in the next commit, or to discard with
gco <file>
.
e.g., committed to development
, meant to commit to feature/xyz
.
- Get the sha of the commit from
git log
ondevelopment
. -
gco feature/xyz
andgit cherry-pick <sha>
. You may have to resolve conflicts here. -
gco development
andgit reset --hard HEAD^
- Finally,
gco feature/xyz
and continue working.
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
- oh-my-zsh git plugin cheatsheet: https://github.com/robbyrussell/oh-my-zsh/wiki/Plugin:git
- advanced git aliases: https://github.com/jlegrone/git-config