From 6843c26f6b2db7720c6a3bfbb2f21c1aeb5468c9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 11 Jul 2025 02:45:16 +0000 Subject: [PATCH] chore: auto-generate README.md from toc-source.json --- contents/apply-diff-file.md | 6 ++++++ contents/apply-patch-with-commit-metadata.md | 6 ++++++ contents/check-existing-worktrees.md | 6 ++++++ contents/cleanup-branches-fast.md | 9 +++++++++ contents/create-a-new-worktree.md | 6 ++++++ contents/create-patch-from-last-commit-s.md | 12 ++++++++++++ .../create-patch-from-uncommitted-changes.md | 6 ++++++ ...e-local-branches-whose-remote-is-gone-bash.md | 15 +++++++++++++++ ...l-branches-whose-remote-is-gone-powershell.md | 16 ++++++++++++++++ ...ean-remove-untracked-files-and-directories.md | 6 ++++++ contents/git-clone-mirror-repository.md | 6 ++++++ contents/git-essentials-hidden-gems.md | 9 +++++++++ contents/git-init-bare.md | 6 ++++++ contents/git-maintenance-start.md | 15 +++++++++++++++ contents/git-replace-old-commit-new-commit.md | 6 ++++++ contents/git-request-pull.md | 15 +++++++++++++++ ...ow-to-use-git-push-force-with-lease-safely.md | 6 ++++++ ...ll-changes-of-specific-files-from-a-commit.md | 6 ++++++ contents/remove-a-worktree.md | 6 ++++++ .../see-who-last-modified-each-line-blame.md | 6 ++++++ .../show-commit-history-of-a-specific-file.md | 6 ++++++ .../show-commit-history-with-author-and-date.md | 6 ++++++ .../show-detailed-commit-history-with-changes.md | 6 ++++++ contents/switch-between-worktrees.md | 6 ++++++ contents/use-worktrees-for-temporary-fixes.md | 6 ++++++ .../view-and-clean-up-local-git-branches-bash.md | 15 +++++++++++++++ ...and-clean-up-local-git-branches-powershell.md | 15 +++++++++++++++ 27 files changed, 229 insertions(+) diff --git a/contents/apply-diff-file.md b/contents/apply-diff-file.md index 4c0b58b..c5d73d6 100644 --- a/contents/apply-diff-file.md +++ b/contents/apply-diff-file.md @@ -19,6 +19,12 @@ git apply changes.diff ```sh git apply changes.diff ``` +- **Show what would change if the diff were applied.** + + +```sh +git apply --stat changes.diff +``` #### Steps diff --git a/contents/apply-patch-with-commit-metadata.md b/contents/apply-patch-with-commit-metadata.md index f3172a1..fb3465c 100644 --- a/contents/apply-patch-with-commit-metadata.md +++ b/contents/apply-patch-with-commit-metadata.md @@ -19,6 +19,12 @@ git am my-changes.patch ```sh git am my-changes.patch ``` +- **Apply a patch and add a Signed-off-by line.** + + +```sh +git am --signoff my-changes.patch +``` #### Steps diff --git a/contents/check-existing-worktrees.md b/contents/check-existing-worktrees.md index 0d0f72e..5f0a803 100644 --- a/contents/check-existing-worktrees.md +++ b/contents/check-existing-worktrees.md @@ -17,6 +17,12 @@ git worktree list ```sh git worktree list ``` +- **List worktrees in a machine-readable format.** + + +```sh +git worktree list --porcelain +``` #### Steps diff --git a/contents/cleanup-branches-fast.md b/contents/cleanup-branches-fast.md index 986eac6..0333b39 100644 --- a/contents/cleanup-branches-fast.md +++ b/contents/cleanup-branches-fast.md @@ -6,6 +6,15 @@ ![Category: Branch Management](https://img.shields.io/badge/Category-Branch%20Management-blue) > Quickly view and clean up local branches using Bash or PowerShell, including removing branches whose remote is gone. + +#### ProTips +> [!TIP] +> Run 'git fetch -p' before cleaning up branches to update remote info. + +> [!TIP] +> Always double-check which branches will be deleted. + + ## Key Topics & Subcommands - [Delete Local Branches Whose Remote is Gone (Bash)](./delete-local-branches-whose-remote-is-gone-bash.md): Delete all local branches whose remote counterpart has been deleted, using Bash. - [Delete Local Branches Whose Remote is Gone (PowerShell)](./delete-local-branches-whose-remote-is-gone-powershell.md): Delete all local branches whose remote counterpart has been deleted, using PowerShell. diff --git a/contents/create-a-new-worktree.md b/contents/create-a-new-worktree.md index df21ca3..cb5dd16 100644 --- a/contents/create-a-new-worktree.md +++ b/contents/create-a-new-worktree.md @@ -19,6 +19,12 @@ git worktree add ```sh git worktree add ../feature-branch feature ``` +- **Create a worktree for a hotfix branch.** + + +```sh +git worktree add ../hotfix hotfix-branch +``` #### Steps diff --git a/contents/create-patch-from-last-commit-s.md b/contents/create-patch-from-last-commit-s.md index 5372b1c..40196fc 100644 --- a/contents/create-patch-from-last-commit-s.md +++ b/contents/create-patch-from-last-commit-s.md @@ -23,6 +23,18 @@ git format-patch HEAD~1 ```sh git format-patch origin/main..HEAD --stdout > my-changes.patch ``` +- **Create patch files for the last two commits.** + + +```sh +git format-patch -2 +``` +- **Create patch files for all commits since main.** + + +```sh +git format-patch -2 origin/main..HEAD +``` #### Steps diff --git a/contents/create-patch-from-uncommitted-changes.md b/contents/create-patch-from-uncommitted-changes.md index 608db0f..76741b0 100644 --- a/contents/create-patch-from-uncommitted-changes.md +++ b/contents/create-patch-from-uncommitted-changes.md @@ -19,6 +19,12 @@ git diff > changes.diff ```sh git diff > changes.diff ``` +- **Create a diff file for the last commit.** + + +```sh +git diff HEAD~1 > last-commit.diff +``` #### Steps diff --git a/contents/delete-local-branches-whose-remote-is-gone-bash.md b/contents/delete-local-branches-whose-remote-is-gone-bash.md index 2392cf8..85ac787 100644 --- a/contents/delete-local-branches-whose-remote-is-gone-bash.md +++ b/contents/delete-local-branches-whose-remote-is-gone-bash.md @@ -19,6 +19,12 @@ git fetch -p && git branch -vv | grep '\[origin/.*: gone\]' | awk '{print $1}' | ```sh git fetch -p && git branch -vv | grep '\[origin/.*: gone\]' | awk '{print $1}' | xargs -r git branch -d ``` +- **Delete only feature branches whose remote is gone.** + + +```sh +git fetch -p && git branch -vv | grep '\[origin/feature: gone\]' | awk '{print $1}' | xargs -r git branch -d +``` #### Steps @@ -32,6 +38,15 @@ git fetch -p && git branch -vv | grep '\[origin/.*: gone\]' | awk '{print $1}' | - ⚠️ Make sure you have no unmerged work on these branches. +#### ProTips +> [!TIP] +> Use this after deleting branches on the remote to keep your local repo tidy. + +> [!TIP] +> Add 'echo' before 'git branch -d' to preview what will be deleted. + + + [➡️ See the Next Step: Delete Local Branches Whose Remote is Gone (PowerShell)](./delete-local-branches-whose-remote-is-gone-powershell.md) --- diff --git a/contents/delete-local-branches-whose-remote-is-gone-powershell.md b/contents/delete-local-branches-whose-remote-is-gone-powershell.md index f7b2807..a68e951 100644 --- a/contents/delete-local-branches-whose-remote-is-gone-powershell.md +++ b/contents/delete-local-branches-whose-remote-is-gone-powershell.md @@ -23,6 +23,13 @@ git branch -vv | ForEach-Object { if ($_ -match '\[.*: gone\]') { $parts = $_.Tr git fetch -p git branch -vv | ForEach-Object { if ($_ -match '[.*: gone]') { $parts = $_.Trim() -split '\s+'; $branch = $parts[0]; if ($branch -ne '') { git branch -d $branch } } } ``` +- **Delete only feature branches whose remote is gone.** + + +```sh +git fetch -p +git branch -vv | ForEach-Object { if ($_ -match '[origin/feature: gone]') { $parts = $_.Trim() -split 's+'; $branch = $parts[0]; if ($branch -ne '') { git branch -d $branch } } } +``` #### Steps @@ -36,6 +43,15 @@ git branch -vv | ForEach-Object { if ($_ -match '[.*: gone]') { $parts = $_.Trim - ⚠️ Make sure you have no unmerged work on these branches. +#### ProTips +> [!TIP] +> Great for Windows users to automate branch cleanup. + +> [!TIP] +> Review the list before confirming deletion. + + + [➡️ See the Next Step: View and Clean Up Local Git Branches (Bash)](./view-and-clean-up-local-git-branches-bash.md) --- diff --git a/contents/git-clean-remove-untracked-files-and-directories.md b/contents/git-clean-remove-untracked-files-and-directories.md index 05be31e..024404b 100644 --- a/contents/git-clean-remove-untracked-files-and-directories.md +++ b/contents/git-clean-remove-untracked-files-and-directories.md @@ -48,6 +48,12 @@ git clean -f -d ```sh git clean -i ``` +- **Delete untracked and ignored files.** + + +```sh +git clean -f -x +``` #### Steps diff --git a/contents/git-clone-mirror-repository.md b/contents/git-clone-mirror-repository.md index 7e5035c..bc8c20e 100644 --- a/contents/git-clone-mirror-repository.md +++ b/contents/git-clone-mirror-repository.md @@ -21,6 +21,12 @@ git clone --mirror https://github.com/example/repo.git ```sh git clone --mirror https://github.com/example/repo.git ``` +- **Mirror-clone a private repo using SSH.** + + +```sh +git clone --mirror git@github.com:org/repo.git +``` #### Steps diff --git a/contents/git-essentials-hidden-gems.md b/contents/git-essentials-hidden-gems.md index af85e1c..f44d5e6 100644 --- a/contents/git-essentials-hidden-gems.md +++ b/contents/git-essentials-hidden-gems.md @@ -8,6 +8,15 @@ A collection of practical, lesser-known, and foundational Git commands that are useful for all users. Start here to discover commands that can improve your workflow and understanding of Git. + +#### ProTips +> [!TIP] +> Try these commands in a test repo before using them on important projects. + +> [!TIP] +> Bookmark this section for quick reference to hidden gems. + + ## Key Topics & Subcommands - [git maintenance start](./git-maintenance-start.md): Runs a cronJob in background for the specified repo for periodic maintenance. - [git request-pull](./git-request-pull.md): Generate a request to pull changes into a repository. diff --git a/contents/git-init-bare.md b/contents/git-init-bare.md index 16312a9..28e0ac2 100644 --- a/contents/git-init-bare.md +++ b/contents/git-init-bare.md @@ -19,6 +19,12 @@ git init --bare my-repo.git ```sh git init --bare my-repo.git ``` +- **Initialize a bare repo in a custom directory for server hosting.** + + +```sh +git init --bare /srv/git/project.git +``` #### Steps diff --git a/contents/git-maintenance-start.md b/contents/git-maintenance-start.md index 3b92c47..9bd1fff 100644 --- a/contents/git-maintenance-start.md +++ b/contents/git-maintenance-start.md @@ -19,12 +19,27 @@ git maintenance start ```sh git maintenance start ``` +- **Run maintenance tasks every hour for more active repos.** + + +```sh +git maintenance start --schedule=hourly +``` #### Steps 1. Run `git maintenance start` in your repository. +#### ProTips +> [!TIP] +> Set up maintenance on large repos to keep them fast. + +> [!TIP] +> Use with cron or scheduled tasks for automation. + + + #### Links - [Official Docs](https://git-scm.com/docs/git-maintenance) diff --git a/contents/git-replace-old-commit-new-commit.md b/contents/git-replace-old-commit-new-commit.md index 95cdc03..a75b9c1 100644 --- a/contents/git-replace-old-commit-new-commit.md +++ b/contents/git-replace-old-commit-new-commit.md @@ -19,6 +19,12 @@ git replace abc123 def456 ```sh git replace abc123 def456 ``` +- **Graft a new parent onto a commit for testing history changes.** + + +```sh +git replace --graft HEAD~2 HEAD +``` #### Steps diff --git a/contents/git-request-pull.md b/contents/git-request-pull.md index a3d1b08..3991b11 100644 --- a/contents/git-request-pull.md +++ b/contents/git-request-pull.md @@ -21,12 +21,27 @@ git request-pull ```sh git request-pull v1.0 https://github.com/example/repo.git v1.1 ``` +- **Request a pull for a feature branch based on main.** + + +```sh +git request-pull main https://github.com/example/repo.git feature-branch +``` #### Steps 1. Run `git request-pull ` to generate a pull request message. +#### ProTips +> [!TIP] +> Use request-pull to generate a summary for code reviews. + +> [!TIP] +> Include a clear start and end point for clarity. + + + #### Links - [Official Docs](https://git-scm.com/docs/git-request-pull) diff --git a/contents/how-to-use-git-push-force-with-lease-safely.md b/contents/how-to-use-git-push-force-with-lease-safely.md index 885c465..70f034d 100644 --- a/contents/how-to-use-git-push-force-with-lease-safely.md +++ b/contents/how-to-use-git-push-force-with-lease-safely.md @@ -21,6 +21,12 @@ git push --force-with-lease ```sh git push --force-with-lease ``` +- **Force-push a specific branch with lease protection.** + + +```sh +git push --force-with-lease origin feature-branch +``` #### Steps diff --git a/contents/pull-changes-of-specific-files-from-a-commit.md b/contents/pull-changes-of-specific-files-from-a-commit.md index e18e5a3..d5cc217 100644 --- a/contents/pull-changes-of-specific-files-from-a-commit.md +++ b/contents/pull-changes-of-specific-files-from-a-commit.md @@ -29,6 +29,12 @@ git add path/to/file1.txt path/to/file2.txt git commit -m "Pulled changes for file1.txt and file2.txt from commit e8ab7f64" git push origin revert/productionOrder ``` +- **Restore files using the newer 'git restore' command.** + + +```sh +git restore --source e8ab7f64fdfcc7bdaaed8d96c0ac26dce035663f path/to/file1.txt path/to/file2.txt +``` #### Steps diff --git a/contents/remove-a-worktree.md b/contents/remove-a-worktree.md index 3039108..5652833 100644 --- a/contents/remove-a-worktree.md +++ b/contents/remove-a-worktree.md @@ -19,6 +19,12 @@ git worktree remove ```sh git worktree remove ../feature-branch ``` +- **Remove a hotfix worktree.** + + +```sh +git worktree remove ../hotfix +``` #### Steps diff --git a/contents/see-who-last-modified-each-line-blame.md b/contents/see-who-last-modified-each-line-blame.md index dd76833..5ab5885 100644 --- a/contents/see-who-last-modified-each-line-blame.md +++ b/contents/see-who-last-modified-each-line-blame.md @@ -19,6 +19,12 @@ git blame filename.txt ```sh git blame filename.txt ``` +- **Blame only lines 10 to 20 of a file.** + + +```sh +git blame -L 10,20 filename.txt +``` #### Steps diff --git a/contents/show-commit-history-of-a-specific-file.md b/contents/show-commit-history-of-a-specific-file.md index 134ef6b..9bc93c1 100644 --- a/contents/show-commit-history-of-a-specific-file.md +++ b/contents/show-commit-history-of-a-specific-file.md @@ -17,6 +17,12 @@ git log --oneline -- filename.txt ```sh git log --oneline -- filename.txt ``` +- **Show commit history for a different file.** + + +```sh +git log --oneline -- path/to/anotherfile.js +``` #### Steps diff --git a/contents/show-commit-history-with-author-and-date.md b/contents/show-commit-history-with-author-and-date.md index 8e2ffeb..b027e18 100644 --- a/contents/show-commit-history-with-author-and-date.md +++ b/contents/show-commit-history-with-author-and-date.md @@ -19,6 +19,12 @@ git log --pretty=format:"%h - %an, %ar : %s" -- filename.txt ```sh git log --pretty=format:"%h - %an, %ar : %s" -- filename.txt ``` +- **Show commit hash, short date, author, and message.** + + +```sh +git log --pretty=format:'%h | %ad | %an | %s' --date=short -- filename.txt +``` #### Steps diff --git a/contents/show-detailed-commit-history-with-changes.md b/contents/show-detailed-commit-history-with-changes.md index 987b31f..c1bea88 100644 --- a/contents/show-detailed-commit-history-with-changes.md +++ b/contents/show-detailed-commit-history-with-changes.md @@ -19,6 +19,12 @@ git log -p -- filename.txt ```sh git log -p -- filename.txt ``` +- **Show the last two commits and their changes for a file.** + + +```sh +git log -p -2 -- filename.txt +``` #### Steps diff --git a/contents/switch-between-worktrees.md b/contents/switch-between-worktrees.md index 4a674ed..49109af 100644 --- a/contents/switch-between-worktrees.md +++ b/contents/switch-between-worktrees.md @@ -17,6 +17,12 @@ ```sh cd ../feature-branch ``` +- **Switch to a hotfix worktree.** + + +```sh +cd ../hotfix +``` #### Steps diff --git a/contents/use-worktrees-for-temporary-fixes.md b/contents/use-worktrees-for-temporary-fixes.md index d82d379..f635c66 100644 --- a/contents/use-worktrees-for-temporary-fixes.md +++ b/contents/use-worktrees-for-temporary-fixes.md @@ -19,6 +19,12 @@ git worktree add ../hotfix hotfix-branch ```sh git worktree add ../hotfix hotfix-branch ``` +- **Create a worktree for a bugfix branch.** + + +```sh +git worktree add ../bugfix bugfix-branch +``` #### Steps diff --git a/contents/view-and-clean-up-local-git-branches-bash.md b/contents/view-and-clean-up-local-git-branches-bash.md index 70ea0d9..1489585 100644 --- a/contents/view-and-clean-up-local-git-branches-bash.md +++ b/contents/view-and-clean-up-local-git-branches-bash.md @@ -22,6 +22,12 @@ git branch -vv | grep -E '^\s*\S+\s+[^\[]+$' ```sh git branch -vv | grep -E '^\s*\S+\s+[^\[]+$' | awk '{print $1}' | xargs git branch -D ``` +- **List branches whose remote is gone.** + + +```sh +git branch -vv | grep 'gone' +``` #### Steps @@ -35,6 +41,15 @@ git branch -vv | grep -E '^\s*\S+\s+[^\[]+$' | awk '{print $1}' | xargs git bran - ⚠️ Deleting branches is irreversible. Double-check before running destructive commands. +#### ProTips +> [!TIP] +> Use 'git branch -vv' to see tracking info for all branches. + +> [!TIP] +> Pipe to 'awk' and 'xargs' for batch deletion. + + + [➡️ See the Next Step: View and Clean Up Local Git Branches (PowerShell)](./view-and-clean-up-local-git-branches-powershell.md) --- diff --git a/contents/view-and-clean-up-local-git-branches-powershell.md b/contents/view-and-clean-up-local-git-branches-powershell.md index 24978ce..bff7c5e 100644 --- a/contents/view-and-clean-up-local-git-branches-powershell.md +++ b/contents/view-and-clean-up-local-git-branches-powershell.md @@ -22,6 +22,12 @@ git branch -vv | Select-String -NotMatch "origin/" ```sh git branch -vv | Select-String -NotMatch "origin/" | ForEach-Object { $branch = ($_ -split "\s+")[1]; git branch -D $branch } ``` +- **List branches whose remote is gone.** + + +```sh +git branch -vv | Select-String 'gone' +``` #### Steps @@ -35,6 +41,15 @@ git branch -vv | Select-String -NotMatch "origin/" | ForEach-Object { $branch = - ⚠️ Deleting branches is irreversible. Double-check before running destructive commands. +#### ProTips +> [!TIP] +> Use PowerShell's 'Select-String' for flexible filtering. + +> [!TIP] +> Automate cleanup with a script for regular maintenance. + + + --- _Author: mike-rambil • Updated: 2024-06-10 • Tags: branches, cleanup, powershell_