Share tips and tricks that I have found useful that I wish someone had shown me when I was first getting started. And even after years of experience. I'm hoping to keep this light on opinions and heavy on the tips and tricks. I'll try, anyways... x_x This piece is assuming you have at minimum a general/working knowledge of git.
- Brief history / comparison
- Brief overview
- Actual tips & tricks w/ live examples
- Resources
Before there was git, there was....
- svn
- cvs
- rcs
- so so so many others
Okokokokokokokokok. So why git?
- It's local. You get the whole repo/world when you clone
- Distributed model. Not a single point of failure. Every copy of a repo is a complete repo on it's own
- can rewrite the history! Ex/ squashing, rebasing, etc.
- Merging (from multiple sources) is a breeze
- Lots of handy functionality. Some highlights on that below
- working copy
- staging area
- repository
Working in a git repo:
- local changes (local, unstaged, uncommitted)
- staging area (local, uncommitted)
- repository (local, committed)
- remote (non-local, committed)
flowchart TB
subgraph wd[working directory]
n1(local changes)
end
subgraph staging[staging area]
n2(test)
end
subgraph repo[repository]
n3(test)
end
subgraph origin[origin]
n4('remote' named 'origin' </br> by convention)
end
wd -- git add --> staging
staging -- git reset HEAD -- --> wd
staging -- git commit --> repo
repo -- it's complicated ... </br> git reset HEAD^ --> staging
repo -- git push origin HEAD --> origin
origin -- N/A --> repo
- git aliases
- simple ones
- multi-command functions
- etc.
- git log
- Use the git log !!!!!
- Help make it more useful. Craft better commit messages!
- Hopefully understanding what the log can do helps to show what makes a good commit message
- only as good as you make it... squash your commits AND messages
- filenames
- search by string
- graphs
- skim/jump/etc commit messages
git log+/${SEARCH_STRING}git log --onelinegit log --patchgit show ${COMMIT}# JUST that specific commitgit diff origin HEAD#git apply ~/my-git-patch
- git reflog
- recover lost branch, commits, etc.
- recover unnitended changes
- git cherry-pick
- git patch + git apply
- git rebase
git rebase -i HEAD~4git rebase -i HEAD^^^^-ifor "interactive"
- git diff
- Diffs are human AND machine readable !
git diff origin HEADgit diff HEADgit diff maingit diff origin/main
- Diffs are human AND machine readable !