- workspace/working tree
current file system - index/staging area
add
-ed,rm
-ed, ready for commit - local repo
committed,HEAD
commit - upstream/remote
a bare repo topush
to - stash
temporary area to store your changes
10 Years of Git: An Interview with Git Creator Linus Torvalds - The Linux Foundation
The Architecture and History of Git: A Distributed Version Control System
The History Behind Git - DEV Community
Tech Talk: Linus Torvalds on git - YouTube
[Linux.conf.au 2013] - Git For Ages 4 And Up - YouTube
The Biggest Misconception About Git – David Gohberg – Medium
History of Git | Hackaday
git - the simple guide - no deep shit!
Opinionated Git
Coding Career Advice: Using Git for Version Control Effectively · Mark's Dev Blog ❗!important
You can always check reflog to restore commit no matter how you messed with your tree.
Git back to the future | Phil Nash
Git concepts in less than 10 minutes | Opensource.com
Git Explained in 100 Seconds - YouTube
13 Advanced (but useful) Git Techniques and Shortcuts - YouTube
Highlights from Git 2.21 - The GitHub Blog
Highlights from Git 2.22 - The GitHub Blog
git man page generator fake git man page
Lokaltog/git-man-page-generator: Git man page generator.
evil git man page
dellis23/evil-git-man-page-generator: An evil fork of this project, no warnings https://github.com/Lokaltog/baba-git-man-page-generator
Tutorials
12 Best Resources to Learn Git Online for FREE in 2023 - DEV Community 👩💻👨💻
Learn git concepts, not commands - DEV Community 👩💻👨💻
Git: A Complete Guide. Covering the essential commands for a… | by Rahul Pathak | Towards Data Science
benthayer/git-gud: Wanna git gud? Then get git-gud, and git gud at git!
Git Tutorials and Training | Atlassian Git Tutorial ❗!important
Using Git - GitHub Docs "Git Handbook"
git - the simple guide - no deep shit!
Git Tutorial - Try Git
GitHub Training Kit - GitHub Cheatsheets source
git ready » learn git one commit at a time
Git Immersion - Brought to you by Neo guided tour
Learn Version Control with Git for Free
Home // Think Like (a) Git
Git Succinctly - Tuts+ Code Tutorials
A Beginner's Git and GitHub Tutorial | Udacity
Understanding Git Conceptually
Getting Started With Git - DZone - Refcardz
Introduction to Git: Installation, Usage, and Branches | DigitalOcean
Git for Teams — Git for Teams — Creating efficiency for teams of one or more.
Learn Git in 30 Minutes | Tutorialzine
Git 版本控制系統 | ihower 的 Git 教室
Learn Git Branching ❗!important
Interactive Git Tutorials – Rebase and Bisect – zwischenzugs
How to become a Git expert
Git It Right » Linux Magazine
Many Branches » Linux Magazine
The Ultimate GIT 5-day Challenge | Udemy
Getting Started With Git: Key Concepts for Beginners | Udemy
Short and Sweet: Get Started with Git and GitHub Right Now | Udemy
Practical Git for Everyday Professional Use from @trevordmiller on @eggheadio
Git for Professionals Tutorial - Tools & Concepts for Mastering Version Control with Git - YouTube
Git and GitHub for Beginners - Crash Course - YouTube
Understanding Git's Behaviour • Steve Smith - YouTube
Introduction to Git - Core Concepts - YouTube
Lecture 6: Version Control (git) (2020) - YouTube
Git Tutorial for Beginners - Git & GitHub Fundamentals In Depth - YouTube
Git And GitHub in ~30 Minutes - YouTube
How to be a git expert - YouTube 46:25
Books
Pro Git
Git Community Book
"Pro Git" Cliff Notes | Jason Meridth Blog
Git Magic - Preface
Git for Everyone
Learn Enough Git to Be Dangerous | Learn Enough to Be Dangerous
Learn Version Control with Git
Manual/Reference/Fucked Up
Git - Documentation
kernel.org user manual
kernel.org howto
Git Reference
Git SCM Wiki
Git Memo
First Aid git
First Aid Kit for Git | Learn Version Control with Git
Dangit, git!
k88hudson/git-flight-rules: Flight rules for git
Git Protocols
Git - The Protocols
Introducing Git protocol version 2 | Google Open Source Blog
Git Wire Protocol, Version 2
Commentaries/Internals
Git - Plumbing and Porcelain
Merkle tree - Wikiwand
The Git Parable
Plastic SCM blog: Linus Torvalds on GIT and SCM
Scaling git's merge and rename-detection machinery | Palantir Blog
Optimizing git’s merge machinery, #2 | by Palantir | Palantir Blog | Mar, 2021 | Medium
How Git Works Under the Hood
Git from the Bottom Up
Reset Demystified – Scott Chacon
Note to Self – Scott Chacon
Git Loves the Environment – Scott Chacon
When You “Git” in Trouble: a Version Control Story – Hacker Noon
Commits are snapshots, not diffs | The GitHub Blog
Git from the inside out - YouTube
Git Internals - How Git Works - Fear Not The SHA! - YouTube
Git Internals by John Britton of GitHub - CS50 Tech Talk - YouTube
How GIT works UNDER the HOOD? - YouTube
Git from the inside out
Unpacking Git packfiles
Git Pathspecs and How to Use Them | CSS-Tricks
How Git truly works. A deep dive on the internals to… | by Alberto Prospero | May, 2022 | Towards Data Science
Get up to speed with partial clone and shallow clone - The GitHub Blog
Git Source Code Review
The Architecture of Open Source Applications (Volume 2): Git
pluralsight/git-internals-pdf
Remediating the May 2018 Git Security Vulnerability | Azure DevOps Blog .git/
which contains user script was pushed to remote and allows remote code execution
Repo size
Reduce repository size - Atlassian Documentation
BFG Repo-Cleaner by rtyley
Rewriting Git project history with The BFG | Info | theguardian.com
Bindings
libgit2 source
notatestuser/gift: A wrapper for the Git CLI in Node.js
Plugins
stevemao/awesome-git-addons: A curated list of addons that extends git cli.
fabiospampinato/awesome-autogit: Curated list of resources for autogit.
Autogit | Autogit
Introduction - complate wiki
complate — command-line utility in Rust // Lib.rs
donnemartin/gitsome: A supercharged Git/GitHub command line interface (CLI).
qw3rtman/gg: Git Goodies: At-A-Glance, Efficient, and Aesthetically Pleasing Git Shortcuts
golbin/git-commander: A git tool with an easy terminal interface.
nvie/gitflow: Git extensions to provide high-level repository operations for Vincent Driessen's branching model.
tj/git-extras video commands
nlf/git-gh: github extensions for git
hub · the command-line wrapper for git github/hub
Gitsu: User management and pairing for Git
You can name you custom script as git-mycmd
, place it in you PATH and use git mycmd
to invoke it.
Extending Git: add a custom command
Extend Git with Custom Commands
Extending Git functionality - Stack Overflow
Atlassian Blogs: Extending git
GUI Clients
Git - GUI Clients
Sourcetree | Free Git GUI for Mac and Windows ❗!important, by Atlassian
Sublime Merge - Git Client, done Sublime ❗!important
GitLens: where have you been all my life! - DEV Community 👩💻👨💻 ❗!important, VSCode extension
Git GUI for Windows, Mac & Linux | GitKraken subscription
GitEye | CollabNet
GitUp Mac only, innovative UX
FredrikNoren/ungit: The easiest way to use git. On any platform. Anywhere.
Git Cola: The highly caffeinated Git GUI
Make Git easy with Git Cola | Opensource.com
Supercharging the Git Commit Graph | Azure DevOps Blog
Supercharging the Git Commit Graph II: File Format | Azure DevOps Blog
Supercharging the Git Commit Graph III: Generations and Graph Algorithms | Azure DevOps Blog
Supercharging the Git Commit Graph IV: Bloom Filters | Azure DevOps Blog
Terminal GUI
extrawurst/gitui: Blazing 💥 fast terminal-ui for git written in rust 🦀 👍
chriswalz/bit: Bit is a modern Git CLI 👍
Tig: text-mode interface for Git 👎
The Tig Manual
tig: nice text-mode (ncurses) Git repo viewer - YouTube
git ready » tig, the ncurses front-end to Git
git? tig! | Atlassian Blogs
Blob
git-annex add file to git
joeyh/git-annex: manage large files with git
Git Large File Storage | Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.
Installation · git-lfs/git-lfs Wiki
Tutorial · git-lfs/git-lfs Wiki
cloudmazing/lfs-server-go: LFS server with multiple file stores and backing stores
Large Media overview | Netlify Docs
Git Large File Storage - How to Work with Big Files - YouTube
Managing huge files on the right storage with Git LFS - YouTube
GitLFS - How to handle large files in Git - Lars Schneider - FOSSASIA Summit 2017 - YouTube
VFS for Git: Git at Enterprise Scale formerly GVFS
Microsoft/VFSForGit: Virtual File System for Git: Enable Git at Enterprise Scale
Workflow
Git Branching Model
A successful Git branching model » nvie.com
Understanding the GitHub Flow · GitHub Guides
a simple git branching model
GitHub Workflow ⋆ Mark McDonnell
GitHub Flow – Scott Chacon
How to GitHub: Fork, Branch, Track, Squash and Pull Request - Gun.io
Git Branching Strategies for Maintainable Test Automation - DZone DevOps
How to Use Git and Git Workflows – a Practical Guide
Git Workflow | Atlassian Git Tutorial
I prefer this flow:
Please stop recommending Git Flow! – George Stocker
What is Trunk-Based Development?
stevenharman/git-workflows
reenhanced/gitreflow
hub · the command-line wrapper for git
My Git Workflow
Commit Policies
Git Flow:
master
: release candidate, release, and hotfixdevelop
: gatekeeper branch, parent of feature branches, CI/CD- merge hotfix on
master
todevelop
Truck:
master
: parent of feature branches, CI/CD
Commits to master
kicks off CI/CD
Rebase
A Rebase Workflow for Git | RandyFay.com
Avoiding Git Disasters: A Gory Story | RandyFay.com
Merging vs. Rebasing | Atlassian Git Tutorial
Merge or Rebase? | SourceTree Blog
Learn Git Rebase Interactively – zwischenzugs
Github workflow · servo/servo Wiki
rebase --interactive --autosquash
fixup
version control - git workflow and rebase vs merge questions - Stack Overflow
version control - When do you use git rebase instead of git merge? - Stack Overflow
Video
Git The Basics Tutorial - excess.org
Tech Talk: Linus Torvalds on git - YouTube
GitHub Training & Guides - YouTube
GOTO 2015 • Deep Dive into Git • Edward Thomson - YouTube
TechDays 2017 - Edward Thomson - Inside Git - YouTube
Introduction to Git with Scott Chacon of GitHub - YouTube
Advanced Git: Graphs, Hashes, and Compression, Oh My! - YouTube
Presentations
schacon/tale_of_three_trees
schacon/showoff-wrangling-git
May need puppetlabs/showoff
Tips and Tricks
git-tips/tips: Most commonly used git tips and tricks.
nirajpandkar/git-tip: CLI that gives a random git-tip.
A few git tips you didn't know about
25 Tips for Intermediate Git Users
Git tips and tricks
GIT Conventions — Medium
10 Git Commands You Should Know – Towards Data Science
10 insanely useful Git commands you wish existed - and their alternatives - datree
git Archives - Everything CLI
Five Key Git Concepts Explained the Hard Way – zwischenzugs
Create Your Own Git Diagrams – zwischenzugs
Martin Heinz - Advanced Git Features You Didn’t Know You Needed
GIT_SSL_NO_VERIFY=true git clone https://url
A Guide To Undoing Mistakes With Git (Part 1) — Smashing Magazine
A Guide To Undoing Mistakes With Git (Part 2) — Smashing Magazine
Presentations: Using Git Effectively · Mark's Dev Blog
tryexceptpass - Episode 6 - Underused Git Commands that Simplify Your Life
How (and why!) to keep your Git commit history clean | GitLab
Git tips: 合并 commit 保持分支干净整洁 – 尘埃落定
The Elements of Commit Style
6 best practices for teams using Git | Opensource.com
Rewriting History
Git - git-filter-branch Documentation
newren/git-filter-repo: Quickly rewrite git repository history (filter-branch replacement) recommended replacement for git filter-branch
Advanced Git Commands: Rewriting History - DZone Open Source
Rewriting Your Git History and JS Source for Fun and Profit · Mark's Dev Blog repo transform with git filter-branch
, pygit2
, pylter-branch
BFG Repo-Cleaner by rtyley cleanse big files/secrets from repo
Githooks
Git Hooks | Learn how to use pre-commit hooks, post-commit hooks, post-receive hooks, and more. | Matthew Hudson
How I Learned to Stop Worrying and Love Git Hooks | CSS-Tricks
How to write custom Git hooks and publishing your code to a website | Opensource.com
okonet/lint-staged: 🚫💩 — Run linters on git staged files
typicode/husky: Git hooks made easy
Using lint-staged, husky, and pre-commit hooks to fail fast and early
Koan
Git Cheatsheet • NDP Software
AOSP Git and Repo cheatsheet
Explain Git with D3
Oh Shit, Git!?!
Conditional config
Edward Thomson: Git Conditional Includes
Use folder prefix to include different gitconfig
Specify SSH key to use
Starting from Git 2.3.0
ssh - How to tell git which private key to use? - Super User
Connecting to GitHub with SSH - User Documentation
GIT_SSH_COMMAND="ssh -vv -i ~/.ssh/KEY" git clone
# `-F` ignores default SSH config
git config --local core.sshCommand "ssh -i ~/.ssh/KEY -F /dev/null"
Credentials other than SSH key
The Vanilla DevOps Git Credentials & Private Packages Cheatsheet
Git - git-credential-store Documentation
Change author
drrb/gitsu: User management and pairing for Git
Adds git su
subcommand to set user from ~/.gitsu
.
git - How to change the commit author for one specific commit? - Stack Overflow
# amend last commit
git commit --amend --author "New Author <new@email>"
How can I change the author (name / email) of a commit? | Learn Version Control with Git
# amend several commits, useful for not yet pushed commits
git rebase -i HEAD^5 # or committish
# pick commits to change author to `edit`
# for each commit
git commit --amend --author "New Author <new@email>" --no-edit
git rebase --continue
#!/bin/sh
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --env-filter '
OLD_EMAIL="leesei@gmail.com"
CORRECT_NAME="Seasoned Bits Solutions"
CORRECT_EMAIL="seasoned.bits@gmail.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
Merging from forked repo
Syncing a fork - User Documentation
Updating Slate · lord/slate Wiki
# setup fork origin as upstream
git remote add upstream <fork origin url>
# pull the latest changes from upstream
git fetch upstream
git fetch upstream --tags
# assuming you are on <feature> branch and have uncommitted updates
git stash
git co master
# rebase forked repo to upstream's master
git rebase upstream/master
# push the updates changes to our fork
git push origin master
git push origin --tags
# rebase <feature> branch onto latest code from master (expect conflicts)
# can also used before submitting pull request/push to repo
git co <feature>
git rebase master
# apply uncommitted changes
git stash pop
push empty commits
this is to re-trigger githooks
git commit --allow-empty -m "Trigger git hook"
commits after release
# get latest tag on current branch
git describe --abbrev=0 --tags
# show commits since latest tag
git log `git describe --tags --abbrev=0`..HEAD --oneline
force pull
git fetch origin main
git reset --hard FETCH_HEAD
git clean -df
updating master
# assuming you have a <feature> branch and have committed updates
git co master
git stash
# merge feature branch to master, squashing to a single commit
git merge --squash feature
update (unpushed) commit message
# last commit
git commit --amend
# older commits
# you can also reorder, squash the commits
git rebase -i HEAD~n # last n commits
git rebase -i $parent_of_flawed_commit
# use 'r' to reword commits
Edit an incorrect commit message in Git - Stack Overflow
Changing a commit message - User Documentation
check diff before merge
How to check real git diff before merging from remote branch? - Stack Overflow
show files on another branch/commit
git show git show <committish>:<path/to/file>
Display a file from another branch - DEV Community 👩💻👨💻
list changed files
git diff-index --shortstat HEAD
Cherry-picking changes to add
git add --patch <file>
git add -p <file>
Commit only part of a file in Git - Stack Overflow
Git - git-add Documentation
Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]?
Here is a description of each option:
- y stage this hunk for the next commit
- n do not stage this hunk for the next commit
- q quit; do not stage this hunk or any of the remaining hunks
- a stage this hunk and all later hunks in the file
- d do not stage this hunk or any of the later hunks in the file
- g select a hunk to go to
- / search for a hunk matching the given regex
- j leave this hunk undecided, see next undecided hunk
- J leave this hunk undecided, see next hunk
- k leave this hunk undecided, see previous undecided hunk
- K leave this hunk undecided, see previous hunk
- s split the current hunk into smaller hunks
- e manually edit the current hunk
- ? print hunk help
drop changes
# replace `file` in file system with copy in local repo
git checkout -- <file>
# unadd
git reset HEAD
# uncommit, changes still added to staging
git reset --soft
# reset local repo and workspace to upstream
git reset --hard origin/master
check unpushed commits
git log --branches --not --remotes
# Git 2.5+
git log @{push}
Deleting branch
# delete remote branch
git push origin :<branch>
# delete local branch
git branch -d <branch>
# delete local branch (force)
git branch -D <branch>
Renaming branch
git branch -m old_branch new_branch # Rename branch locally
# push and set default branch to new_branch if using GitHub
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
Set tracking branch
git branch --set-upstream feature_branch origin/origin_branch
# checkout and track
git checkout -t origin/feature
# push and track
git push -u origin feature
rebase
git pull --rebase
git rebase HEAD feature && git rebase HEAD @{-2}
abandoning merge
git merge --abort # git > 1.7.4
git reset --merge # git < 1.7.4
git reset --hard HEAD # git < 1.6.2
create repo archive
git archive master -o <repo>.<tag>.zip
# deploy to server
git archive --format=tar origin/master | gzip -9c | ssh user@yourserver.com "tar --directory=/var/www -xvzf -"
Tagging and pushing tag to GitHub will aldo allow you to download the zipped code.
reduce repo size
How to Shrink a Git Repository
What is git gc and how does it work? | Atlassian Git Tutorial
Reduce git repository size - Stack Overflow
Git pull error: unable to create temporary sha1 filename - Stack Overflow
Optimize your repository using Git GC | by Ameet Prajapati | codeburst
git fsck # show dangling (orphaned) commit
git gc --aggressive --prune=now
git reflog expire --expire-unreachable=now --all git gc --prune=now
worktree
local fork with merge helpers
Git - git-worktree Documentation
Using multiple working trees in Git - DEV Community 👩💻👨💻
Experiment on your code freely with Git worktree | Opensource.com
Get current branch
git branch --show-current # Git 2.22+
git rev-parse --abbrev-ref HEAD
Rebase feature branch
git reset --soft master
Commits count
This can be used as build number
git rev-list --count <branch>
difftool/mergetool
Using diff-so-fancy
/dunk
as PAGER
Git - git-difftool Documentation
Git - git-mergetool Documentation
Setting up and using Meld as your git difftool and mergetool - Stack Overflow
git merge - How to set Meld as git mergetool - Stack Overflow
Git Tutorial: Diff and Merge Tools - YouTube
The EXTREMELY helpful guide to merge conflicts - YouTube
VS Code's 3-way Merge Editor
so-fancy/diff-so-fancy: Good-lookin' diffs. Actually… nah… The best-lookin' diffs. :tada:
darrenburns/dunk: Prettier git diffs in the terminal 🎨
vimdiff
A better Vimdiff Git mergetool | Vim Tips Wiki | FANDOM powered by Wikia
Use vimdiff as git mergetool - Ruslan Osipov
sparse-checkout
Git - git-sparse-checkout Documentation
Bring your monorepo down to size with sparse-checkout - The GitHub Blog
如何在 Monorepo 透過 Git 的 Sparse Checkout 取得部分 Repo 內容 | The Will Will Web use cone mode
Partial clone | GitLab
submodules
Submodule saves a commit hash of another (library) repo in the current (master) repo
Mastering Git submodules — Medium
using project with submodules
# clone project with submodules
git clone --recursive
# for cloned project
git submodule update --init
# update local submodule hash
git submodule update --remote
git submodule sync
git submodule status
subtree
git/git-subtree.txt at master · git/git
Alternatives To Git Submodule: Git Subtree
The power of Git subtree - Atlassian Developers
Mastering Git subtrees — Medium
Understanding Git Subtree - HPC @ Uni.lu
git migrate from submodule to subtree | Life & Note - winterTTr
Old notes
git checkout -b redesign
# update working branch
git pull origin
git merge master
# OR
? git pull origin master:redesign
# commit
git pull origin
git checkout master
git merge redesign
git push origin master:master
# OR
git checkout redesign
git rebase master
git push origin redesign:master
# delete local branch
git branch -d redesign # after merge
git branch -D redesign # force
# delete remote branch
git push origin :redesign
# delete whole tree
git push origin :master
# diff staged with index
git diff --staged # alias of --cached
# update a commit (unpushed)
git commit --amend <file>
# show commit info
git log [<some/path>]
git show [<some commit id>]
Fossil
Fossil: Home
Chisel - Fossil SCM Hosting
No-brainer SCM with Fossil