git Note

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

RemoteRepositoryLocalRepositoryStagingAreaWorkingDirectoryRemoteRepositoryLocalRepositoryStagingAreaWorkingDirectory📝 Basic Workflow🔄 Synchronization & Remote🌿 Branch Managementgit cherry-pick -x commit-hashgit 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-checkgit for-each-ref --format='%(refname:short)'3️⃣ Maintenance:git gc --autogit repack -dgit maintenance start4️⃣ Debugging:git bisect run npm testgit blame -w -C -C -CGIT_TRACE=1 git commandgit add . (Stage all)1git add -p (Interactive staging)2git add -N (Intent to add)3git add --chmod=+x file4git commit -m "feat: new feature"5git commit --amend6git commit --fixup=HEAD7git commit --date="2 days ago"8git push origin main9git push --force-with-lease10git push --follow-tags11git push --all12Confirm push success13Update HEAD pointer14Clear staged changes15git fetch --all --prune --tags16git fetch origin branch:branch17git remote add upstream URL18git remote set-url origin URL19git pull --rebase origin main20git pull --ff-only21git pull --autostash22git pull --allow-unrelated-histories23Confirm sync complete24Update tracking refs25git branch feature/new26git branch -D old-branch27git branch --merged28git branch --no-merged29git checkout feature/new30git checkout -b feature/new upstream/feature31git switch -c new-branch32git switch - (Previous branch)33git merge --squash feature34git merge --strategy-option theirs35git merge --no-ff36git rebase -i HEAD~337git rebase --onto main feature38git rebase --autostash39git stash save "WIP: feature"40git stash list41git stash show -p stash@{0}42git stash branch new-branch43git checkout -- file.txt44git stash pop stash@{0}45git stash apply stash@{0}46git stash drop stash@{0}47git stash clear48git clean -fd49git clean -fX (Remove ignored)50git status -s -b51git status --ignored52git log --graph --oneline --all53git log --follow file.txt54git log -S"string" --patch55git log --author="name"56git diff --cached57git diff branch1...branch258git diff --word-diff59git blame -w -C file.txt60git reflog expire --expire=30.days61git shortlog -sn --no-merges62git rev-parse HEAD63git rev-list --count HEAD64git reset HEAD file.txt65git restore --staged file.txt66git restore --source=HEAD~1 file.txt67git reset --hard HEAD~168git reset --soft HEAD~169git reset --merge ORIG_HEAD70git revert HEAD71git revert --no-commit HEAD~3..72git revert -m 1 HEAD73git filter-branch --tree-filter74git filter-repo --path file.txt75git tag -a v1.0.0 -m "Release"76git tag -s v1.0.0 -m "Signed"77git tag --contains commit-hash78git push --tags79git push --follow-tags80git tag -d old-tag81git tag -l "v1.8.5*"82git fetch --tags83git config --global user.name84git config --global alias.co checkout85git config --global core.editor vim86git config --global merge.tool kdiff387git gc --aggressive88git prune --expire=2.weeks.ago89git fsck --full90git count-objects -v91git verify-pack -v92git submodule add URL path93git submodule update --init --recursive94git submodule foreach git pull95git worktree add path branch96git worktree list97git worktree remove path98prepare-commit-msg hook99pre-commit hook100post-commit hook101pre-push hook102post-merge hook103git bisect start104git bisect good/bad105git grep -n "string"106git archive --format=zip HEAD107git notes add -m "note"108git worktree add -b emergency-fix ../temp HEAD109git maintenance start110
RemoteRepositoryLocalRepositoryStagingAreaWorkingDirectoryDeveloperRemoteRepositoryLocalRepositoryStagingAreaWorkingDirectoryDeveloper🚀 Efficient Daily WorkflowQuick commit with messageConcise status viewInteractive staging for precise commitsUsing the alias we just createdPush & set upstream to current branch📊 History ManagementInteractive rebase for clean historyAutomatic squashing of fixup commitsRebase & stash in one command🔍 Advanced InspectionColored, formatted log outputContributor statisticsSearch history for code changesDetect code movement & ignore whitespace🔧 Maintenance & CleanupEnable background maintenanceDeep repository optimizationRemove all untracked & ignored filesClean old reflog entries🐛 Debugging ToolsAutomatic bug findingDebug Git operations💼 Working with BranchesQuick switch to previous branchList merged branchesFind work in progressList branches by last commit🔒 Safety & RecoveryPrevent accidental mergesSafe force pushDescriptive stash entriesTrack all ref changes🚄 Performance TipsShallow clone for large reposClone without file contentGet full history when neededSkip hooks for quick commits🔗 Integration WorkflowFetch PR for local testingRe-target branch baseCombine feature as one commitTrack cherry-picked commits• Configure SSH keys with multiple identitiesgit config --global alias.cm "commit -am"1git config --global alias.st "status -sb"2git add -p3git cm "feat: new feature"4git push -u origin HEAD5git rebase -i HEAD~36git commit --fixup=HEAD~17git rebase -i --autosquash HEAD~38git pull --rebase --autostash9git log --pretty=format:"%C(yellow)%h %C(blue)%ad %C(red)%an %C(green)%s"10git shortlog -sn --all --no-merges11git log -G"pattern" --patch12git blame -w -C -C file.txt13git maintenance start14git gc --aggressive --prune=now15git clean -fdx16git reflog expire --expire=30.days17git bisect start18git bisect bad HEAD19git bisect good HEAD~1020git bisect run npm test21GIT_TRACE=1 git status22git checkout -23git branch --merged main24git branch --no-merged25git for-each-ref --sort=-committerdate refs/heads/26git config --global merge.ff only27git push --force-with-lease28git stash save "WIP: description"29git reflog show --all30git clone --depth 131git clone --filter=blob:none32git fetch --unshallow33git commit --no-verify34git fetch origin pull/123/head:pr-12335git rebase --onto main feature bug-fix36git merge --squash feature37git cherry-pick -x commit-hash38
RemoteRepositoryLocalRepositoryStagingAreaWorkingDirectoryDeveloperRemoteRepositoryLocalRepositoryStagingAreaWorkingDirectoryDeveloper🚀 Efficient Daily WorkflowSet up alias for quick commits with messageCreate alias for concise status viewStage changes interactively for precise commitsUse alias to stage and commit in one commandPush and set upstream to current branch name📊 History ManagementClean up last 3 commits interactivelyMark commit to be squashed laterAutomatically arrange and squash fixup commitsStash, rebase and pop changes automatically🔍 Advanced InspectionCustom colored log output with hash, date, author, messageList all contributors sorted by commit countSearch commit history for code pattern changesTrack line changes while ignoring whitespace and detecting moves🔧 Maintenance & CleanupSchedule regular background maintenance tasksAggressively optimize repository size and performanceRemove all untracked and ignored files recursivelyRemove old reflog entries older than 30 days🐛 Debugging ToolsInitialize binary search for bugMark current version as brokenMark older version as workingAutomate bug finding with test commandEnable detailed Git operation logging💼 Branch ManagementSwitch to previously checked out branchShow branches merged into mainList branches with unmerged changesList branches sorted by last commit date🔒 Safety & RecoveryPrevent accidental merge commitsForce push only if remote hasn't changedSave work-in-progress with clear descriptionView history of all ref updates🚄 Performance TipsClone only latest commit for faster downloadClone without file contents initiallyDownload full history when neededSkip pre-commit hooks for faster commits🔗 Integration WorkflowFetch PR locally for testingMove bug-fix branch onto main branchCombine all feature commits into oneCopy commit with reference to original• Enable auto-correction: git config --global help.autocorrect 1git config --global alias.cm "commit -am"1git config --global alias.st "status -sb"2git add -p3git cm "feat: new feature"4git push -u origin HEAD5git rebase -i HEAD~36git commit --fixup=HEAD~17git rebase -i --autosquash HEAD~38git pull --rebase --autostash9git log --pretty=format:"%C(yellow)%h %C(blue)%ad %C(red)%an %C(green)%s"10git shortlog -sn --all --no-merges11git log -G"pattern" --patch12git blame -w -C -C file.txt13git maintenance start14git gc --aggressive --prune=now15git clean -fdx16git reflog expire --expire=30.days17git bisect start18git bisect bad HEAD19git bisect good HEAD~1020git bisect run npm test21GIT_TRACE=1 git status22git checkout -23git branch --merged main24git branch --no-merged25git for-each-ref --sort=-committerdate refs/heads/26git config --global merge.ff only27git push --force-with-lease28git stash save "WIP: description"29git reflog show --all30git clone --depth 131git clone --filter=blob:none32git fetch --unshallow33git commit --no-verify34git fetch origin pull/123/head:pr-12335git rebase --onto main feature bug-fix36git merge --squash feature37git cherry-pick -x commit-hash38
RemoteRepositoryLocalRepositoryStagingAreaWorkingDirectoryDeveloper🚀 Efficient Daily WorkflowSet up alias for quick commits with messagegit config --global alias.cm "commit -am"1
git config --global credential.helper cache
Bash
dependencyIIIIII
init
config▪️credential1
▪️user name2
▪️email3
▪️line color4
▪️GPG key5
Temporary Commits

  1. git config --global credential.helper store[↩]
  2. git config --global user.name "[name]"[↩]
  3. git config --global user.email "[email]"[↩]
  4. git config --global color.ui auto[↩]
  5. git config --global user.signingkey "[key]"[↩]

Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *