Introduction
- Git Tutorial β’ 6 video playlist β’ Ben Kadel πΊ
- Git Tutorials β’ 7 video playlist explaining git basics on a whiteboard β’ GitKraken πΊ
General
- Git by example: Interactive guide β’ Anton Zhiyanov π
Undoing mistakes
- How to undo (almost) anything with Git β’ GitHub Blog π
Branching & Merging
- How to branch off of a feature branch (while you wait for the feature branch to be merged):
- In GitHub flow, is it OK to base feature branch on another feature branch? β’ Stack Exchange π©βπ»
- Resolving a merge conflict:
- The EXTREMELY helpful guide to merge conflicts β’ Starts with a great explanation (with visuals) of what a merge conflict actually is, followed by a walkthrough of how to use a 3-way merge editor to resolve one β’ Visual Studio Code πΊ
- Lazygit if simple enough to chose one side or the other
- VS Code if more complex? Neovim?
- Reverting a merge:
- Deleting merged branches:
- Clean up your Git branches β’ Jamie Tanna π
- Wait, what does a BRANCH do again? β’ A branch is a pointer to a single commit; itβs not a collection of related commits β’ GitKraken πΊ
Searching Git History
git log
- cli approach
- search entire git history for any text with
git log -S <string>
- Search all of Git history for a string - Stack Overflow
- works by searching all diffs that add or remove an instance of that string (i.e. that changed how many references to that string there were)
- use
-G
instead of-S
to simply find all diff lines that match the regexp (regardless of whether the number of instances in the file changed)
- use
- gives a list of commits with diffs that contain the search string
- add
-p
to the command to see the diffs too in aless
pager you can search with/
or page through withctrl-f/b
- is there a way to configure git to send the output of
git log -S <search string>
to vim (the way I do with kittyβs scrollback buffer / command output)?- or, can I at least
cat
everything instead of paging it withless
so that I can then send the kitty output to nvim my usual way?
- or, can I at least
- search entire git history for any text with
- lazygit
- vs code / GitLens
- vim fugitive
- Git log customization β’ Justin Joyce π
- improve my
git log
output in Lazygit? - improve my
git log
output in CLI?
- improve my
Searching current codebase
- avoiding noisy git matches (beginner - intermediate) anthony explains β’ Using a
.gitattributes
file to mark certain files as binary so their contents wonβt cluttergit grep
results β’ Anthony Writes Code πΊ
Committing
- Git commit and commit message best practices β’ Commit focused changes often with short, descriptive messages that make those commits easy to squash or revert later without unintended side effects β’ Justin Joyce π
- How atomic Git commits dramatically increased my productivity - and will increase yours too β’ Samuel-Zacharie Faure π
- git add -p β’ Julia Evans π
Diffing
- Git Diff β’ Basic CLI output using
--stat
to see just the list of changed files with their changed line counts β’ Justin Joyce π - quick way to diff two text blocks? e.g. was just on a call where a few lines were thought to be the same (and could be extracted), but that was determined just by eyeballing β what would be a better alternative to prove whether the text is actually the same?
Forking
- Configuring a remote repository for a fork β’ You must configure a remote that points to the upstream repository in Git to sync changes you make in a fork with the original repository. This also allows you to sync changes made in the original repository with the fork β’ GitHub Docs π
- Git commands to keep a fork up to date β’ Phil Nash π
- Syncing a fork β’ GitHub Docs π
- Clean up a fork and restart it from the upstream β’ Stack Overflow π©βπ»
- Force your forked repo to be the same as upstream β’ Glenn Block π©βπ»
- Syncing your fork to the original repository via the browser β’ Kirstie Jane π©βπ»
- Quick Tip: Sync a Fork with the Original via GitHubβs Web UI β’ Bruno Skvorc
- Creating a pull request from a fork β’ GitHub Docs π
Configuration
- Popular git config options β’ Julia Evans π
- Better git diff with delta β’ Pawel Grzybek π
- Sorting Git branches β’ Cassidy Williams π
- is a global ignore file a bad practice when collaborating? would it be better not to have it so I/we am/are prompted to ignore those files at the project level?
- prompted by a project that included (didnβt ignore) some source files in a
dist/
directory - after using one for awhile, I think itβs actually not great when working on shared projects
- prompted by a project that included (didnβt ignore) some source files in a
Git worktrees
- How I Use Git Worktrees β’ One tree per concurrent workflow, rather than one per branch β’ Matklad π
- use via Lazygit?
- use via VS Code?
- use via neovim?
- Git Worktrees and Neovim: A Match Made in Coding Heaven β’ DevOps Toolbox πΊ
Other concepts
- How HEAD works in git β’ Julia Evans π
Inbox
-
.git-blame-ignore-revs
file:- Ignore commits in the blame view β’ GitHub Docs π
-
Git is my buddy: Effective Git as a solo developer β’ Mikkel Paulson π
-
How to merge multiple Git repos and keep their commit history β’ Graham F. Scott π
-
Some miscellaneous git facts β’ Julia Evans π
-
revert a commit to main that wasnβt a pr: open a new branch from main; revert commit; push changes; open pr; merge pr (could also just revert commit directly, but this is how to use a pr workflow for a commit reversion)
-
Whatβs a βfixupβ commit? When would I use them?
-
git - How to download a folder from github? - Stack Overflow - how to download a folder from a repo via curl
-
executing a git pull from a different directory - Stack Overflow - You can execute
git
commands in a different directory usinggit -C <repo-directory> <command>
- Stack Overflow -
How to level up your Git game with GitHub CLI - The GitHub Blog β’ Lots of examples of the available commands β’ GitHub Blog π
-
diffdiff - Awesome in-browser diff tool