I’ve always trying to summarize an article of how to use git, but there has been a lot of resistance of doing so, one reason is that there are sufficient material that have enough info of how to use git. Although they provide a very detailed info regarding how to use git, I or beginners may find it bafffling to incorporate that into my daily workflow since there are a lot of options and arguments to be memorized.
What I’ve found is that the best way to learn it is to use it. This claim sounds really vague and would not actually provide anything meaningful. What I meant is that it would be better that a reader needs to run a repo code on local machine and remote server, collaborate with other people, efficiently develop the code with various git techniques. Git would makes more sense when one is trying to deal with a large code base and need to manage the development workflow back and forth. Those info provided online are good but it seems that they could not be able to make an impact on readers who want to get started.
I have to admit that with new generations of editors including VS Code, users don’t need to remember all the intricate commands, plugins are also able to provide commit messages that are actually pretty good. You could definitely use ChatGPT or Claude to generate the commands based on the prompt.
Thus based on the arguments I provided above, in this post I just want to provide a high level summary for git, so that readers know how to get started, to use git without memorizing all the commands. In one episodes of Friends, Ross Geller is trying to list all 50 states with lots of difficulties in Thanksgiving. My goal is definitely not asking you to remember all the commands, but to let you know where California or Washington is, and how to plan a road trip to NYC and how to handle the basic issues during the trip.
Note that in the beginning, just try to work on or become comfortable with the fundamental ones, which does not require other concepts. Once you are comfortable with the fundamental blocks, you could work all the way up.
https://education.github.com/git-cheat-sheet-education.pdf
Remote Repository Local Repository Staging Area Working Directory Remote Repository Local Repository Staging Area Working Directory 📝 Basic Workflow 🔄 Synchronization & Remote 🌿 Branch Management git cherry-pick -x commit-hash git cherry-pick --no-commit commit-hash ⚡ Temporary Storage 🔍 Inspection & Comparison ↩️ History Modification 🏷️ Tags & Releases 🔧 Config & Maintenance 📦 Submodules & Worktrees 🎣 Hooks & Automation 🔀 Advanced Operations 💡 Pro Tips: 1️⃣ Efficient Workflow: git commit -am "message" (Add & commit) git push -u origin branch (Set upstream) git pull --rebase (Keep history clean) 2️⃣ Advanced Usage: git log --pretty=format:"%h %an %s" git rev-list --objects --all | git cat-file --batch-check git for-each-ref --format='%(refname:short)' 3️⃣ Maintenance: git gc --auto git repack -d git maintenance start 4️⃣ Debugging: git bisect run npm test git blame -w -C -C -C GIT_TRACE=1 git command git add . (Stage all) 1 git add -p (Interactive staging) 2 git add -N (Intent to add) 3 git add --chmod=+x file 4 git commit -m "feat: new feature" 5 git commit --amend 6 git commit --fixup=HEAD 7 git commit --date="2 days ago" 8 git push origin main 9 git push --force-with-lease 10 git push --follow-tags 11 git push --all 12 Confirm push success 13 Update HEAD pointer 14 Clear staged changes 15 git fetch --all --prune --tags 16 git fetch origin branch:branch 17 git remote add upstream URL 18 git remote set-url origin URL 19 git pull --rebase origin main 20 git pull --ff-only 21 git pull --autostash 22 git pull --allow-unrelated-histories 23 Confirm sync complete 24 Update tracking refs 25 git branch feature/new 26 git branch -D old-branch 27 git branch --merged 28 git branch --no-merged 29 git checkout feature/new 30 git checkout -b feature/new upstream/feature 31 git switch -c new-branch 32 git switch - (Previous branch) 33 git merge --squash feature 34 git merge --strategy-option theirs 35 git merge --no-ff 36 git rebase -i HEAD~3 37 git rebase --onto main feature 38 git rebase --autostash 39 git stash save "WIP: feature" 40 git stash list 41 git stash show -p stash@{0} 42 git stash branch new-branch 43 git checkout -- file.txt 44 git stash pop stash@{0} 45 git stash apply stash@{0} 46 git stash drop stash@{0} 47 git stash clear 48 git clean -fd 49 git clean -fX (Remove ignored) 50 git status -s -b 51 git status --ignored 52 git log --graph --oneline --all 53 git log --follow file.txt 54 git log -S"string" --patch 55 git log --author="name" 56 git diff --cached 57 git diff branch1...branch2 58 git diff --word-diff 59 git blame -w -C file.txt 60 git reflog expire --expire=30.days 61 git shortlog -sn --no-merges 62 git rev-parse HEAD 63 git rev-list --count HEAD 64 git reset HEAD file.txt 65 git restore --staged file.txt 66 git restore --source=HEAD~1 file.txt 67 git reset --hard HEAD~1 68 git reset --soft HEAD~1 69 git reset --merge ORIG_HEAD 70 git revert HEAD 71 git revert --no-commit HEAD~3.. 72 git revert -m 1 HEAD 73 git filter-branch --tree-filter 74 git filter-repo --path file.txt 75 git tag -a v1.0.0 -m "Release" 76 git tag -s v1.0.0 -m "Signed" 77 git tag --contains commit-hash 78 git push --tags 79 git push --follow-tags 80 git tag -d old-tag 81 git tag -l "v1.8.5*" 82 git fetch --tags 83 git config --global user.name 84 git config --global alias.co checkout 85 git config --global core.editor vim 86 git config --global merge.tool kdiff3 87 git gc --aggressive 88 git prune --expire=2.weeks.ago 89 git fsck --full 90 git count-objects -v 91 git verify-pack -v 92 git submodule add URL path 93 git submodule update --init --recursive 94 git submodule foreach git pull 95 git worktree add path branch 96 git worktree list 97 git worktree remove path 98 prepare-commit-msg hook 99 pre-commit hook 100 post-commit hook 101 pre-push hook 102 post-merge hook 103 git bisect start 104 git bisect good/bad 105 git grep -n "string" 106 git archive --format=zip HEAD 107 git notes add -m "note" 108 git worktree add -b emergency-fix ../temp HEAD 109 git maintenance start 110
Remote Repository Local Repository Staging Area Working Directory Developer Remote Repository Local Repository Staging Area Working Directory Developer 🚀 Efficient Daily Workflow Quick commit with message Concise status view Interactive staging for precise commits Using the alias we just created Push & set upstream to current branch 📊 History Management Interactive rebase for clean history Automatic squashing of fixup commits Rebase & stash in one command 🔍 Advanced Inspection Colored, formatted log output Contributor statistics Search history for code changes Detect code movement & ignore whitespace 🔧 Maintenance & Cleanup Enable background maintenance Deep repository optimization Remove all untracked & ignored files Clean old reflog entries 🐛 Debugging Tools Automatic bug finding Debug Git operations 💼 Working with Branches Quick switch to previous branch List merged branches Find work in progress List branches by last commit 🔒 Safety & Recovery Prevent accidental merges Safe force push Descriptive stash entries Track all ref changes 🚄 Performance Tips Shallow clone for large repos Clone without file content Get full history when needed Skip hooks for quick commits 🔗 Integration Workflow Fetch PR for local testing Re-target branch base Combine feature as one commit Track cherry-picked commits • Configure SSH keys with multiple identities git config --global alias.cm "commit -am" 1 git config --global alias.st "status -sb" 2 git add -p 3 git cm "feat: new feature" 4 git push -u origin HEAD 5 git rebase -i HEAD~3 6 git commit --fixup=HEAD~1 7 git rebase -i --autosquash HEAD~3 8 git pull --rebase --autostash 9 git log --pretty=format:"%C(yellow)%h %C(blue)%ad %C(red)%an %C(green)%s" 10 git shortlog -sn --all --no-merges 11 git log -G"pattern" --patch 12 git blame -w -C -C file.txt 13 git maintenance start 14 git gc --aggressive --prune=now 15 git clean -fdx 16 git reflog expire --expire=30.days 17 git bisect start 18 git bisect bad HEAD 19 git bisect good HEAD~10 20 git bisect run npm test 21 GIT_TRACE=1 git status 22 git checkout - 23 git branch --merged main 24 git branch --no-merged 25 git for-each-ref --sort=-committerdate refs/heads/ 26 git config --global merge.ff only 27 git push --force-with-lease 28 git stash save "WIP: description" 29 git reflog show --all 30 git clone --depth 1 31 git clone --filter=blob:none 32 git fetch --unshallow 33 git commit --no-verify 34 git fetch origin pull/123/head:pr-123 35 git rebase --onto main feature bug-fix 36 git merge --squash feature 37 git cherry-pick -x commit-hash 38
Remote Repository Local Repository Staging Area Working Directory Developer Remote Repository Local Repository Staging Area Working Directory Developer 🚀 Efficient Daily Workflow Set up alias for quick commits with message Create alias for concise status view Stage changes interactively for precise commits Use alias to stage and commit in one command Push and set upstream to current branch name 📊 History Management Clean up last 3 commits interactively Mark commit to be squashed later Automatically arrange and squash fixup commits Stash, rebase and pop changes automatically 🔍 Advanced Inspection Custom colored log output with hash, date, author, message List all contributors sorted by commit count Search commit history for code pattern changes Track line changes while ignoring whitespace and detecting moves 🔧 Maintenance & Cleanup Schedule regular background maintenance tasks Aggressively optimize repository size and performance Remove all untracked and ignored files recursively Remove old reflog entries older than 30 days 🐛 Debugging Tools Initialize binary search for bug Mark current version as broken Mark older version as working Automate bug finding with test command Enable detailed Git operation logging 💼 Branch Management Switch to previously checked out branch Show branches merged into main List branches with unmerged changes List branches sorted by last commit date 🔒 Safety & Recovery Prevent accidental merge commits Force push only if remote hasn't changed Save work-in-progress with clear description View history of all ref updates 🚄 Performance Tips Clone only latest commit for faster download Clone without file contents initially Download full history when needed Skip pre-commit hooks for faster commits 🔗 Integration Workflow Fetch PR locally for testing Move bug-fix branch onto main branch Combine all feature commits into one Copy commit with reference to original • Enable auto-correction: git config --global help.autocorrect 1 git config --global alias.cm "commit -am" 1 git config --global alias.st "status -sb" 2 git add -p 3 git cm "feat: new feature" 4 git push -u origin HEAD 5 git rebase -i HEAD~3 6 git commit --fixup=HEAD~1 7 git rebase -i --autosquash HEAD~3 8 git pull --rebase --autostash 9 git log --pretty=format:"%C(yellow)%h %C(blue)%ad %C(red)%an %C(green)%s" 10 git shortlog -sn --all --no-merges 11 git log -G"pattern" --patch 12 git blame -w -C -C file.txt 13 git maintenance start 14 git gc --aggressive --prune=now 15 git clean -fdx 16 git reflog expire --expire=30.days 17 git bisect start 18 git bisect bad HEAD 19 git bisect good HEAD~10 20 git bisect run npm test 21 GIT_TRACE=1 git status 22 git checkout - 23 git branch --merged main 24 git branch --no-merged 25 git for-each-ref --sort=-committerdate refs/heads/ 26 git config --global merge.ff only 27 git push --force-with-lease 28 git stash save "WIP: description" 29 git reflog show --all 30 git clone --depth 1 31 git clone --filter=blob:none 32 git fetch --unshallow 33 git commit --no-verify 34 git fetch origin pull/123/head:pr-123 35 git rebase --onto main feature bug-fix 36 git merge --squash feature 37 git cherry-pick -x commit-hash 38
Remote Repository Local Repository Staging Area Working Directory Developer 🚀 Efficient Daily Workflow Set up alias for quick commits with message git config --global alias.cm "commit -am" 1
git config --global credential.helper cache
Bash
dependency I II III init config credential user name email line color GPG keyTemporary Commits
Leave a Reply