[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-3108":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":23,"topics":24,"createdAt":10,"pushedAt":10,"updatedAt":27,"readmeContent":28,"aiSummary":29,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":30,"discoverSource":31},3108,"tips","git-tips\u002Ftips","git-tips","Most commonly used git tips and tricks.","http:\u002F\u002Fgit.io\u002Fgit-tips",null,"JavaScript",21702,1713,530,5,0,2,14,72.1,"MIT License",false,"master",true,[25,5,26],"git","tips-and-tricks","2026-06-12 04:00:16","## git-tips\n> Collection of `git-tips`, want to add your tips? Checkout [contributing.md](.\u002Fcontributing.md)\n\n[English](http:\u002F\u002Fgit.io\u002Fgit-tips) | [中文](https:\u002F\u002Fgithub.com\u002F521xueweihan\u002Fgit-tips) | [Русский](https:\u002F\u002Fgithub.com\u002FImangazaliev\u002Fgit-tips) | [한국어](https:\u002F\u002Fgithub.com\u002Fmingrammer\u002Fgit-tips) | [Tiếng Việt](https:\u002F\u002Fgithub.com\u002Fhprobotic\u002Fgit-tips) | [日本語](https:\u002F\u002Fgithub.com\u002Fisotai\u002Fgit-tips) | [नेपाली](https:\u002F\u002Fgithub.com\u002Famarduwal\u002Fgit-tips) | [Polski](https:\u002F\u002Fgithub.com\u002Fmbiesiad\u002Ftips) | [فارسی](https:\u002F\u002Fgithub.com\u002Fjavadnikbakht\u002Fgit-tips)\n\n### __Tools:__\n\n* [git-tip](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fgit-tip) - A handy CLI to make optimum use of these tips. ([Here in Docker container](https:\u002F\u002Fgithub.com\u002Fdjoudi5\u002Fdocker-git-tip))\n\n📖 **[Read the interactive GitBook documentation here!](https:\u002F\u002Fgit-tips.github.io\u002Ftips\u002F)**\n\nP.S: All these commands are tested on `git version 2.7.4 (Apple Git-66)`.\n\n## Table of Contents\n\n* [Basic Operations](#basic-operations)\n  * [List of all files till a commit](#list-of-all-files-till-a-commit)\n  * [Quickly switch to the previous branch](#quickly-switch-to-the-previous-branch)\n  * [Delete remote branch](#delete-remote-branch)\n  * [Delete remote tag](#delete-remote-tag)\n  * [Undo local changes with the content in index(staging)](#undo-local-changes-with-the-content-in-indexstaging)\n  * [Reword the previous commit message](#reword-the-previous-commit-message)\n  * [See commit history for just the current branch](#see-commit-history-for-just-the-current-branch)\n  * [Amend author.](#amend-author)\n  * [Stage parts of a changed file, instead of the entire file](#stage-parts-of-a-changed-file-instead-of-the-entire-file)\n  * [Pick commits across branches using cherry-pick](#pick-commits-across-branches-using-cherry-pick)\n  * [Grab a single file from a stash](#grab-a-single-file-from-a-stash)\n  * [Create new working tree from a repository (git 2.5)](#create-new-working-tree-from-a-repository-git-25)\n  * [Create new working tree from HEAD state](#create-new-working-tree-from-head-state)\n  * [Show all commits in the current branch yet to be merged to master](#show-all-commits-in-the-current-branch-yet-to-be-merged-to-master)\n  * [Modify previous commit without modifying the commit message](#modify-previous-commit-without-modifying-the-commit-message)\n  * [Prunes references to remove branches that have been deleted in the remote.](#prunes-references-to-remove-branches-that-have-been-deleted-in-the-remote)\n  * [Retrieve the commit hash of the initial revision.](#retrieve-the-commit-hash-of-the-initial-revision)\n  * [Import from a bundle](#import-from-a-bundle)\n  * [Ignore one file on commit (e.g. Changelog).](#ignore-one-file-on-commit-eg-changelog)\n  * [Fetch pull request by ID to a local branch](#fetch-pull-request-by-id-to-a-local-branch)\n  * [Restore deleted file.](#restore-deleted-file)\n  * [Restore file to a specific commit-hash](#restore-file-to-a-specific-commit-hash)\n  * [Marks your commit as a fix of a previous commit.](#marks-your-commit-as-a-fix-of-a-previous-commit)\n  * [Skip staging area during commit.](#skip-staging-area-during-commit)\n  * [Interactive staging.](#interactive-staging)\n  * [Status of ignored files.](#status-of-ignored-files)\n  * [Checkout a new branch without any history](#checkout-a-new-branch-without-any-history)\n  * [Find guilty with binary search](#find-guilty-with-binary-search)\n  * [Bypass pre-commit and commit-msg githooks](#bypass-pre-commit-and-commit-msg-githooks)\n  * [Clone a single branch](#clone-a-single-branch)\n  * [Create and switch new branch](#create-and-switch-new-branch)\n  * [Show all local branches ordered by recent commits](#show-all-local-branches-ordered-by-recent-commits)\n  * [Clone a shallow copy of a repository](#clone-a-shallow-copy-of-a-repository)\n  * [Force push to Remote Repository](#force-push-to-remote-repository)\n  * [Group commits by authors and title](#group-commits-by-authors-and-title)\n  * [Forced push but still ensure you don't overwrite other's work](#forced-push-but-still-ensure-you-dont-overwrite-others-work)\n  * [Number of commits in a branch](#number-of-commits-in-a-branch)\n  * [Add object notes](#add-object-notes)\n  * [Apply commit from another repository](#apply-commit-from-another-repository)\n  * [Specific fetch reference](#specific-fetch-reference)\n  * [Generates a summary of pending changes](#generates-a-summary-of-pending-changes)\n  * [Show git status short](#show-git-status-short)\n  * [Checkout a commit prior to a day ago](#checkout-a-commit-prior-to-a-day-ago)\n  * [Push the current branch to the same name on the remote repository](#push-the-current-branch-to-the-same-name-on-the-remote-repository)\n  * [Push a new local branch to remote repository and track](#push-a-new-local-branch-to-remote-repository-and-track)\n  * [Update a submodule to the latest commit](#update-a-submodule-to-the-latest-commit)\n  * [Duplicating a repository](#duplicating-a-repository)\n* [Branching](#branching)\n  * [List all branches that are already merged into master](#list-all-branches-that-are-already-merged-into-master)\n  * [Remove branches that have already been merged with master](#remove-branches-that-have-already-been-merged-with-master)\n  * [List all branches and their upstreams, as well as last commit on branch](#list-all-branches-and-their-upstreams-as-well-as-last-commit-on-branch)\n  * [Track upstream branch](#track-upstream-branch)\n  * [Delete local branch](#delete-local-branch)\n  * [Get list of all local and remote branches](#get-list-of-all-local-and-remote-branches)\n  * [Get only remote branches](#get-only-remote-branches)\n  * [Find out branches containing commit-hash](#find-out-branches-containing-commit-hash)\n  * [Rename a branch](#rename-a-branch)\n  * [Archive the `master` branch](#archive-the-master-branch)\n  * [Delete local branches that has been squash and merged in the remote.](#delete-local-branches-that-has-been-squash-and-merged-in-the-remote)\n  * [Export a branch with history to a file.](#export-a-branch-with-history-to-a-file)\n  * [Get the name of current branch.](#get-the-name-of-current-branch)\n  * [Show the most recent tag on the current branch.](#show-the-most-recent-tag-on-the-current-branch)\n  * [List all branch is WIP](#list-all-branch-is-wip)\n  * [Preformatted patch file.](#preformatted-patch-file)\n  * [Switch to a branch (modern alternative to checkout)](#switch-to-a-branch-modern-alternative-to-checkout)\n* [Log and History](#log-and-history)\n  * [Show helpful guides that come with Git](#show-helpful-guides-that-come-with-git)\n  * [Search change by content](#search-change-by-content)\n  * [Show changes over time for specific file](#show-changes-over-time-for-specific-file)\n  * [List all the conflicted files](#list-all-the-conflicted-files)\n  * [List of all files changed in a commit](#list-of-all-files-changed-in-a-commit)\n  * [Unstaged changes since last commit](#unstaged-changes-since-last-commit)\n  * [Changes staged for commit](#changes-staged-for-commit)\n  * [Show both staged and unstaged changes](#show-both-staged-and-unstaged-changes)\n  * [What changed since two weeks?](#what-changed-since-two-weeks)\n  * [See all commits made since forking from master](#see-all-commits-made-since-forking-from-master)\n  * [Show all tracked files](#show-all-tracked-files)\n  * [Show all untracked files](#show-all-untracked-files)\n  * [Show all ignored files](#show-all-ignored-files)\n  * [Visualize the version tree.](#visualize-the-version-tree)\n  * [Visualize the tree including commits that are only referenced from reflogs](#visualize-the-tree-including-commits-that-are-only-referenced-from-reflogs)\n  * [Show inline word diff.](#show-inline-word-diff)\n  * [Show changes using common diff tools.](#show-changes-using-common-diff-tools)\n  * [Commits in Branch1 that are not in Branch2](#commits-in-branch1-that-are-not-in-branch2)\n  * [List n last commits](#list-n-last-commits)\n  * [Open all conflicted files in an editor.](#open-all-conflicted-files-in-an-editor)\n  * [View the GPG signatures in the commit log](#view-the-gpg-signatures-in-the-commit-log)\n  * [Extract file from another branch.](#extract-file-from-another-branch)\n  * [List only the root and merge commits.](#list-only-the-root-and-merge-commits)\n  * [List commits and changes to a specific file (even through renaming)](#list-commits-and-changes-to-a-specific-file-even-through-renaming)\n  * [Search Commit log across all branches for given text](#search-commit-log-across-all-branches-for-given-text)\n  * [Get first commit in a branch (from master)](#get-first-commit-in-a-branch-from-master)\n  * [Show the author, time and last revision made to each line of a given file](#show-the-author-time-and-last-revision-made-to-each-line-of-a-given-file)\n  * [Show how many lines does an author contribute](#show-how-many-lines-does-an-author-contribute)\n  * [Show all the git-notes](#show-all-the-git-notes)\n  * [List unpushed git commits](#list-unpushed-git-commits)\n  * [Add everything, but whitespace changes](#add-everything-but-whitespace-changes)\n  * [blame on certain range](#blame-on-certain-range)\n  * [Show a Git logical variable.](#show-a-git-logical-variable)\n  * [Get the repo name.](#get-the-repo-name)\n  * [logs between date range](#logs-between-date-range)\n  * [Exclude author from logs](#exclude-author-from-logs)\n  * [View expanded details of changes in last commit](#view-expanded-details-of-changes-in-last-commit)\n  * [Visualize each position of HEAD in the last 30 days](#visualize-each-position-of-head-in-the-last-30-days)\n* [Merging and Rebasing](#merging-and-rebasing)\n  * [Rebases 'feature' to 'master' and merges it in to master ](#rebases-feature-to-master-and-merges-it-in-to-master-)\n  * [Stash changes before rebasing](#stash-changes-before-rebasing)\n  * [Squash fixup commits normal commits.](#squash-fixup-commits-normal-commits)\n  * [Change previous two commits with an interactive rebase.](#change-previous-two-commits-with-an-interactive-rebase)\n  * [Find common ancestor of two branches](#find-common-ancestor-of-two-branches)\n  * [Change a branch base](#change-a-branch-base)\n* [Miscellaneous](#miscellaneous)\n  * [Everyday Git in twenty commands or so](#everyday-git-in-twenty-commands-or-so)\n  * [Untrack files without deleting](#untrack-files-without-deleting)\n  * [Don’t consider changes for tracked file.](#dont-consider-changes-for-tracked-file)\n  * [Check if the change was a part of a release.](#check-if-the-change-was-a-part-of-a-release)\n  * [List ignored files.](#list-ignored-files)\n  * [Count unpacked number of objects and their disk consumption.](#count-unpacked-number-of-objects-and-their-disk-consumption)\n  * [Prune all unreachable objects from the object database.](#prune-all-unreachable-objects-from-the-object-database)\n  * [Instantly browse your working repository in gitweb.](#instantly-browse-your-working-repository-in-gitweb)\n  * [Find lines matching the pattern (regex or string) in tracked files](#find-lines-matching-the-pattern-regex-or-string-in-tracked-files)\n  * [Backup untracked files.](#backup-untracked-files)\n  * [Send a collection of patches as emails](#send-a-collection-of-patches-as-emails)\n* [Remotes](#remotes)\n  * [Changing a remote's URL](#changing-a-remotes-url)\n  * [Get list of all remote references](#get-list-of-all-remote-references)\n  * [Adding Remote name](#adding-remote-name)\n  * [List all currently configured remotes](#list-all-currently-configured-remotes)\n  * [List references in a remote repository](#list-references-in-a-remote-repository)\n  * [Refresh the list of remote branches](#refresh-the-list-of-remote-branches)\n* [Setup and Config](#setup-and-config)\n  * [Remove sensitive data from history, after a push](#remove-sensitive-data-from-history-after-a-push)\n  * [Reset author, after author has been changed in the global config.](#reset-author-after-author-has-been-changed-in-the-global-config)\n  * [Get git bash completion](#get-git-bash-completion)\n  * [Git Aliases](#git-aliases)\n  * [Always rebase instead of merge on pull.](#always-rebase-instead-of-merge-on-pull)\n  * [List all the alias and configs.](#list-all-the-alias-and-configs)\n  * [Make git case sensitive.](#make-git-case-sensitive)\n  * [Add custom editors.](#add-custom-editors)\n  * [Auto correct typos.](#auto-correct-typos)\n  * [Reuse recorded resolution, record and reuse previous conflicts resolutions.](#reuse-recorded-resolution-record-and-reuse-previous-conflicts-resolutions)\n  * [Remove entry in the global config.](#remove-entry-in-the-global-config)\n  * [Ignore file mode changes on commits](#ignore-file-mode-changes-on-commits)\n  * [Turn off git colored terminal output](#turn-off-git-colored-terminal-output)\n  * [Specific color settings](#specific-color-settings)\n  * [Alias: git undo](#alias-git-undo)\n  * [Edit [local\u002Fglobal] git config](#edit-localglobal-git-config)\n  * [List all git aliases](#list-all-git-aliases)\n  * [Use SSH instead of HTTPs for remotes](#use-ssh-instead-of-https-for-remotes)\n  * [Prevent auto replacing LF with CRLF](#prevent-auto-replacing-lf-with-crlf)\n  * [Edit config for each level](#edit-config-for-each-level)\n* [Stashing](#stashing)\n  * [Saving current state of tracked files without committing](#saving-current-state-of-tracked-files-without-committing)\n  * [Saving current state of unstaged changes to tracked files](#saving-current-state-of-unstaged-changes-to-tracked-files)\n  * [Saving current state including untracked files](#saving-current-state-including-untracked-files)\n  * [Saving current state with message](#saving-current-state-with-message)\n  * [Saving current state of all files (ignored, untracked, and tracked)](#saving-current-state-of-all-files-ignored-untracked-and-tracked)\n  * [Show list of all saved stashes](#show-list-of-all-saved-stashes)\n  * [Show the contents of any stash in patch form](#show-the-contents-of-any-stash-in-patch-form)\n  * [Apply any stash without deleting from the stashed list](#apply-any-stash-without-deleting-from-the-stashed-list)\n  * [Apply last stashed state and delete it from stashed list](#apply-last-stashed-state-and-delete-it-from-stashed-list)\n  * [Delete all stored stashes](#delete-all-stored-stashes)\n* [Submodules and Subtrees](#submodules-and-subtrees)\n  * [Update all the submodules](#update-all-the-submodules)\n  * [Deploying git tracked subfolder to gh-pages](#deploying-git-tracked-subfolder-to-gh-pages)\n  * [Adding a project to repo using subtree](#adding-a-project-to-repo-using-subtree)\n  * [Get latest changes in your repo for a linked project using subtree](#get-latest-changes-in-your-repo-for-a-linked-project-using-subtree)\n* [Tagging](#tagging)\n  * [Create local tag](#create-local-tag)\n  * [Delete local tag](#delete-local-tag)\n* [Undoing Changes](#undoing-changes)\n  * [Sync with remote, overwrite local changes](#sync-with-remote-overwrite-local-changes)\n  * [Git reset first commit](#git-reset-first-commit)\n  * [Reset: preserve uncommitted local changes](#reset-preserve-uncommitted-local-changes)\n  * [Revert: Undo a commit by creating a new commit](#revert-undo-a-commit-by-creating-a-new-commit)\n  * [Reset: Discard commits, advised for private branch](#reset-discard-commits-advised-for-private-branch)\n  * [Before deleting untracked files\u002Fdirectory, do a dry run to get the list of these files\u002Fdirectories](#before-deleting-untracked-filesdirectory-do-a-dry-run-to-get-the-list-of-these-filesdirectories)\n  * [Forcefully remove untracked files](#forcefully-remove-untracked-files)\n  * [Forcefully remove untracked directory](#forcefully-remove-untracked-directory)\n  * [Undo assume-unchanged.](#undo-assume-unchanged)\n  * [Clean the files from `.gitignore`.](#clean-the-files-from-gitignore)\n  * [Dry run. (any command that supports dry-run flag should do.)](#dry-run-any-command-that-supports-dry-run-flag-should-do)\n  * [Unstaging Staged file](#unstaging-staged-file)\n  * [Revert: Reverting an entire merge](#revert-reverting-an-entire-merge)\n  * [Restore file (modern alternative to reset\u002Fcheckout --)](#restore-file-modern-alternative-to-resetcheckout---)\n\n## Basic Operations\n\n### List of all files till a commit\n```sh\ngit ls-tree --name-only -r \u003Ccommit-ish>\n```\n\n### Quickly switch to the previous branch\n```sh\ngit checkout -\n```\n**Alternatives:**\n```sh\ngit checkout @{-1}\n```\n\n### Delete remote branch\n```sh\ngit push origin --delete \u003Cremote_branchname>\n```\n**Alternatives:**\n```sh\ngit push origin :\u003Cremote_branchname>\n```\n```sh\ngit branch -dr \u003Cremote\u002Fbranch>\n```\n\n### Delete remote tag\n```sh\ngit push origin :refs\u002Ftags\u002F\u003Ctag-name>\n```\n\n### Undo local changes with the content in index(staging)\n```sh\ngit checkout -- \u003Cfile_name>\n```\n\n### Reword the previous commit message\n```sh\ngit commit -v --amend\n```\n\n### See commit history for just the current branch\n```sh\ngit cherry -v master\n```\n\n### Amend author.\n```sh\ngit commit --amend --author='Author Name \u003Cemail@address.com>'\n```\n\n### Stage parts of a changed file, instead of the entire file\n```sh\ngit add -p\n```\n\n### Pick commits across branches using cherry-pick\n```sh\ngit checkout \u003Cbranch-name> && git cherry-pick \u003Ccommit-ish>\n```\n\n### Grab a single file from a stash\n```sh\ngit checkout \u003Cstash@{n}> -- \u003Cfile_path>\n```\n**Alternatives:**\n```sh\ngit checkout stash@{0} -- \u003Cfile_path>\n```\n\n### Create new working tree from a repository (git 2.5)\n```sh\ngit worktree add -b \u003Cbranch-name> \u003Cpath> \u003Cstart-point>\n```\n\n### Create new working tree from HEAD state\n```sh\ngit worktree add --detach \u003Cpath> HEAD\n```\n\n### Show all commits in the current branch yet to be merged to master\n```sh\ngit cherry -v master\n```\n**Alternatives:**\n```sh\ngit cherry -v master \u003Cbranch-to-be-merged>\n```\n\n### Modify previous commit without modifying the commit message\n```sh\ngit add --all && git commit --amend --no-edit\n```\n\n### Prunes references to remove branches that have been deleted in the remote.\n```sh\ngit fetch -p\n```\n**Alternatives:**\n```sh\ngit remote prune origin\n```\n\n### Retrieve the commit hash of the initial revision.\n```sh\n git rev-list --reverse HEAD | head -1\n```\n**Alternatives:**\n```sh\ngit rev-list --max-parents=0 HEAD\n```\n```sh\ngit log --pretty=oneline | tail -1 | cut -c 1-40\n```\n```sh\ngit log --pretty=oneline --reverse | head -1 | cut -c 1-40\n```\n\n### Import from a bundle\n```sh\ngit clone repo.bundle \u003Crepo-dir> -b \u003Cbranch-name>\n```\n\n### Ignore one file on commit (e.g. Changelog).\n```sh\ngit update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog\n```\n\n### Fetch pull request by ID to a local branch\n```sh\ngit fetch origin pull\u002F\u003Cid>\u002Fhead:\u003Cbranch-name>\n```\n**Alternatives:**\n```sh\ngit pull origin pull\u002F\u003Cid>\u002Fhead:\u003Cbranch-name>\n```\n\n### Restore deleted file.\n```sh\ngit checkout \u003Cdeleting_commit> -- \u003Cfile_path>\n```\n\n### Restore file to a specific commit-hash\n```sh\ngit checkout \u003Ccommit-ish> -- \u003Cfile_path>\n```\n\n### Marks your commit as a fix of a previous commit.\n```sh\ngit commit --fixup \u003CSHA-1>\n```\n\n### Skip staging area during commit.\n```sh\ngit commit --only \u003Cfile_path>\n```\n\n### Interactive staging.\n```sh\ngit add -i\n```\n\n### Status of ignored files.\n```sh\ngit status --ignored\n```\n\n### Checkout a new branch without any history\n```sh\ngit checkout --orphan \u003Cbranch_name>\n```\n\n### Find guilty with binary search\n```sh\ngit bisect start                    # Search start \ngit bisect bad                      # Set point to bad commit \ngit bisect good v2.6.13-rc2         # Set point to good commit|tag \ngit bisect bad                      # Say current state is bad \ngit bisect good                     # Say current state is good \ngit bisect reset                    # Finish search \n\n```\n\n### Bypass pre-commit and commit-msg githooks\n```sh\ngit commit --no-verify\n```\n\n### Clone a single branch\n```sh\ngit clone -b \u003Cbranch-name> --single-branch https:\u002F\u002Fgithub.com\u002Fuser\u002Frepo.git\n```\n\n### Create and switch new branch\n```sh\ngit checkout -b \u003Cbranch-name>\n```\n**Alternatives:**\n```sh\ngit branch \u003Cbranch-name> && git checkout \u003Cbranch-name>\n```\n```sh\ngit switch -c \u003Cbranch-name>\n```\n\n### Show all local branches ordered by recent commits\n```sh\ngit for-each-ref --sort=-committerdate --format='%(refname:short)' refs\u002Fheads\u002F\n```\n\n### Clone a shallow copy of a repository\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002Fuser\u002Frepo.git --depth 1\n```\n\n### Force push to Remote Repository\n```sh\ngit push -f \u003Cremote-name> \u003Cbranch-name>\n```\n\n### Group commits by authors and title\n```sh\ngit shortlog\n```\n\n### Forced push but still ensure you don't overwrite other's work\n```sh\ngit push --force-with-lease \u003Cremote-name> \u003Cbranch-name>\n```\n\n### Number of commits in a branch\n```sh\ngit rev-list --count \u003Cbranch-name>\n```\n\n### Add object notes\n```sh\ngit notes add -m 'Note on the previous commit....'\n```\n\n### Apply commit from another repository\n```sh\ngit --git-dir=\u003Csource-dir>\u002F.git format-patch -k -1 --stdout \u003CSHA1> | git am -3 -k\n```\n\n### Specific fetch reference\n```sh\ngit fetch origin master:refs\u002Fremotes\u002Forigin\u002Fmymaster\n```\n\n### Generates a summary of pending changes\n```sh\ngit request-pull v1.0 https:\u002F\u002Fgit.ko.xz\u002Fproject master:for-linus\n```\n\n### Show git status short\n```sh\ngit status --short --branch\n```\n\n### Checkout a commit prior to a day ago\n```sh\ngit checkout master@{yesterday}\n```\n\n### Push the current branch to the same name on the remote repository\n```sh\ngit push origin HEAD\n```\n\n### Push a new local branch to remote repository and track\n```sh\ngit push -u origin \u003Cbranch_name>\n```\n\n### Update a submodule to the latest commit\n```sh\ncd \u003Cpath-to-submodule>\ngit pull origin \u003Cbranch>\ncd \u003Croot-of-your-main-project>\ngit add \u003Cpath-to-submodule>\ngit commit -m \"submodule updated\"\n```\n\n### Duplicating a repository\n```sh\ngit clone --bare https:\u002F\u002Fgithub.com\u002Fexampleuser\u002Fold-repository.git\n\ngit push --mirror https:\u002F\u002Fgithub.com\u002Fexampleuser\u002Fnew-repository.git\n```\n\n## Branching\n\n### List all branches that are already merged into master\n```sh\ngit branch --merged master\n```\n\n### Remove branches that have already been merged with master\n```sh\ngit branch --merged master | grep -v '^\\*' | xargs -n 1 git branch -d\n```\n**Alternatives:**\n```sh\ngit branch --merged master | grep -v '^\\*\\|  master' | xargs -n 1 git branch -d # will not delete master if master is not checked out\n```\n\n### List all branches and their upstreams, as well as last commit on branch\n```sh\ngit branch -vv\n```\n\n### Track upstream branch\n```sh\ngit branch -u origin\u002Fmybranch\n```\n\n### Delete local branch\n```sh\ngit branch -d \u003Clocal_branchname>\n```\n\n### Get list of all local and remote branches\n```sh\ngit branch -a\n```\n\n### Get only remote branches\n```sh\ngit branch -r\n```\n\n### Find out branches containing commit-hash\n```sh\ngit branch -a --contains \u003Ccommit-ish>\n```\n**Alternatives:**\n```sh\ngit branch --contains \u003Ccommit-ish>\n```\n\n### Rename a branch\n```sh\ngit branch -m \u003Cnew-branch-name>\n```\n**Alternatives:**\n```sh\ngit branch -m [\u003Cold-branch-name>] \u003Cnew-branch-name>\n```\n\n### Archive the `master` branch\n```sh\ngit archive master --format=zip --output=master.zip\n```\n\n### Delete local branches that has been squash and merged in the remote.\n```sh\ngit branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D\n```\n\n### Export a branch with history to a file.\n```sh\ngit bundle create \u003Cfile> \u003Cbranch-name>\n```\n\n### Get the name of current branch.\n```sh\ngit rev-parse --abbrev-ref HEAD\n```\n\n### Show the most recent tag on the current branch.\n```sh\ngit describe --tags --abbrev=0\n```\n\n### List all branch is WIP\n```sh\ngit checkout master && git branch --no-merged\n```\n\n### Preformatted patch file.\n```sh\ngit format-patch -M upstream..topic\n```\n\n### Switch to a branch (modern alternative to checkout)\n```sh\ngit switch \u003Cbranch-name>\n```\n**Alternatives:**\n```sh\ngit switch -c \u003Cnew-branch-name>\n```\n\n## Log and History\n\n### Show helpful guides that come with Git\n```sh\ngit help -g\n```\n\n### Search change by content\n```sh\ngit log -S'\u003Ca term in the source>'\n```\n\n### Show changes over time for specific file\n```sh\ngit log -p \u003Cfile_name>\n```\n\n### List all the conflicted files\n```sh\ngit diff --name-only --diff-filter=U\n```\n\n### List of all files changed in a commit\n```sh\ngit diff-tree --no-commit-id --name-only -r \u003Ccommit-ish>\n```\n\n### Unstaged changes since last commit\n```sh\ngit diff\n```\n\n### Changes staged for commit\n```sh\ngit diff --cached\n```\n**Alternatives:**\n```sh\ngit diff --staged\n```\n\n### Show both staged and unstaged changes\n```sh\ngit diff HEAD\n```\n\n### What changed since two weeks?\n```sh\ngit log --no-merges --raw --since='2 weeks ago'\n```\n**Alternatives:**\n```sh\ngit whatchanged --since='2 weeks ago'\n```\n\n### See all commits made since forking from master\n```sh\ngit log --no-merges --stat --reverse master..\n```\n\n### Show all tracked files\n```sh\ngit ls-files -t\n```\n\n### Show all untracked files\n```sh\ngit ls-files --others\n```\n\n### Show all ignored files\n```sh\ngit ls-files --others -i --exclude-standard\n```\n\n### Visualize the version tree.\n```sh\ngit log --pretty=oneline --graph --decorate --all\n```\n**Alternatives:**\n```sh\ngitk --all\n```\n```sh\ngit log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d'\n```\n\n### Visualize the tree including commits that are only referenced from reflogs\n```sh\ngit log --graph --decorate --oneline $(git rev-list --walk-reflogs --all)\n```\n\n### Show inline word diff.\n```sh\ngit diff --word-diff\n```\n\n### Show changes using common diff tools.\n```sh\ngit difftool [-t \u003Ctool>] \u003Ccommit1> \u003Ccommit2> \u003Cpath>\n```\n\n### Commits in Branch1 that are not in Branch2\n```sh\ngit log Branch1 ^Branch2\n```\n\n### List n last commits\n```sh\ngit log -\u003Cn>\n```\n**Alternatives:**\n```sh\ngit log -n \u003Cn>\n```\n\n### Open all conflicted files in an editor.\n```sh\ngit diff --name-only | uniq | xargs $EDITOR\n```\n\n### View the GPG signatures in the commit log\n```sh\ngit log --show-signature\n```\n\n### Extract file from another branch.\n```sh\ngit show \u003Cbranch_name>:\u003Cfile_name>\n```\n\n### List only the root and merge commits.\n```sh\ngit log --first-parent\n```\n\n### List commits and changes to a specific file (even through renaming)\n```sh\ngit log --follow -p -- \u003Cfile_path>\n```\n\n### Search Commit log across all branches for given text\n```sh\ngit log --all --grep='\u003Cgiven-text>'\n```\n\n### Get first commit in a branch (from master)\n```sh\ngit log --oneline master..\u003Cbranch-name> | tail -1\n```\n**Alternatives:**\n```sh\ngit log --reverse master..\u003Cbranch-name> | head -6\n```\n\n### Show the author, time and last revision made to each line of a given file\n```sh\ngit blame \u003Cfile-name>\n```\n\n### Show how many lines does an author contribute\n```sh\ngit log --author='_Your_Name_Here_' --pretty=tformat: --numstat | gawk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf \"added lines: %s removed lines: %s total lines: %s\n\", add, subs, loc }' -\n```\n**Alternatives:**\n```sh\ngit log --author='_Your_Name_Here_' --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf \"added lines: %s, removed lines: %s, total lines: %s\n\", add, subs, loc }' - # on Mac OSX\n```\n\n### Show all the git-notes\n```sh\ngit log --show-notes='*'\n```\n\n### List unpushed git commits\n```sh\ngit log --branches --not --remotes\n```\n**Alternatives:**\n```sh\ngit log @{u}..\n```\n```sh\ngit cherry -v\n```\n\n### Add everything, but whitespace changes\n```sh\ngit diff --ignore-all-space | git apply --cached\n```\n\n### blame on certain range\n```sh\ngit blame -L \u003Cstart>,\u003Cend>\n```\n\n### Show a Git logical variable.\n```sh\ngit var -l | \u003Cvariable>\n```\n\n### Get the repo name.\n```sh\ngit rev-parse --show-toplevel\n```\n\n### logs between date range\n```sh\ngit log --since='FEB 1 2017' --until='FEB 14 2017'\n```\n\n### Exclude author from logs\n```sh\ngit log --perl-regexp --author='^((?!excluded-author-regex).*)$'\n```\n\n### View expanded details of changes in last commit\n```sh\ngit show\n```\n\n### Visualize each position of HEAD in the last 30 days\n```sh\ngit reflog\n```\n\n## Merging and Rebasing\n\n### Rebases 'feature' to 'master' and merges it in to master \n```sh\ngit rebase master feature && git checkout master && git merge -\n```\n\n### Stash changes before rebasing\n```sh\ngit rebase --autostash\n```\n\n### Squash fixup commits normal commits.\n```sh\ngit rebase -i --autosquash\n```\n\n### Change previous two commits with an interactive rebase.\n```sh\ngit rebase --interactive HEAD~2\n```\n\n### Find common ancestor of two branches\n```sh\ngit merge-base \u003Cbranch-name> \u003Cother-branch-name>\n```\n\n### Change a branch base\n```sh\ngit rebase --onto \u003Cnew_base> \u003Cold_base>\n```\n\n## Miscellaneous\n\n### Everyday Git in twenty commands or so\n```sh\ngit help everyday\n```\n\n### Untrack files without deleting\n```sh\ngit rm --cached \u003Cfile_path>\n```\n**Alternatives:**\n```sh\ngit rm --cached -r \u003Cdirectory_path>\n```\n\n### Don’t consider changes for tracked file.\n```sh\ngit update-index --assume-unchanged \u003Cfile_name>\n```\n\n### Check if the change was a part of a release.\n```sh\ngit name-rev --name-only \u003CSHA-1>\n```\n\n### List ignored files.\n```sh\ngit check-ignore *\n```\n\n### Count unpacked number of objects and their disk consumption.\n```sh\ngit count-objects --human-readable\n```\n\n### Prune all unreachable objects from the object database.\n```sh\ngit gc --prune=now --aggressive\n```\n\n### Instantly browse your working repository in gitweb.\n```sh\ngit instaweb [--local] [--httpd=\u003Chttpd>] [--port=\u003Cport>] [--browser=\u003Cbrowser>]\n```\n\n### Find lines matching the pattern (regex or string) in tracked files\n```sh\ngit grep --heading --line-number 'foo bar'\n```\n\n### Backup untracked files.\n```sh\ngit ls-files --others -i --exclude-standard | xargs zip untracked.zip\n```\n\n### Send a collection of patches as emails\n```sh\ngit send-email [\u003Coptions>] \u003Cfile|directory>…\n\ngit send-email [\u003Coptions>] \u003Cformat-patch options>\n```\n\n## Remotes\n\n### Changing a remote's URL\n```sh\ngit remote set-url origin \u003CURL>\n```\n\n### Get list of all remote references\n```sh\ngit remote\n```\n**Alternatives:**\n```sh\ngit remote show\n```\n\n### Adding Remote name\n```sh\ngit remote add \u003Cremote-nickname> \u003Cremote-url>\n```\n\n### List all currently configured remotes\n```sh\ngit remote -v\n```\n\n### List references in a remote repository\n```sh\ngit ls-remote git:\u002F\u002Fgit.kernel.org\u002Fpub\u002Fscm\u002Fgit\u002Fgit.git\n```\n\n### Refresh the list of remote branches\n```sh\ngit remote update origin --prune\n```\n\n## Setup and Config\n\n### Remove sensitive data from history, after a push\n```sh\ngit filter-branch --force --index-filter 'git rm --cached --ignore-unmatch \u003Cpath-to-your-file>' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all\n```\n\n### Reset author, after author has been changed in the global config.\n```sh\ngit commit --amend --reset-author --no-edit\n```\n\n### Get git bash completion\n```sh\ncurl -L http:\u002F\u002Fgit.io\u002Fvfhol > ~\u002F.git-completion.bash && echo '[ -f ~\u002F.git-completion.bash ] && . ~\u002F.git-completion.bash' >> ~\u002F.bashrc\n```\n\n### Git Aliases\n```sh\ngit config --global alias.\u003Chandle> \u003Ccommand> \ngit config --global alias.st status\n```\n\n### Always rebase instead of merge on pull.\n```sh\ngit config --global pull.rebase true\n```\n**Alternatives:**\n```sh\n#git \u003C 1.7.9\ngit config --global branch.autosetuprebase always\n```\n\n### List all the alias and configs.\n```sh\ngit config --list\n```\n\n### Make git case sensitive.\n```sh\ngit config --global core.ignorecase false\n```\n\n### Add custom editors.\n```sh\ngit config --global core.editor '$EDITOR'\n```\n\n### Auto correct typos.\n```sh\ngit config --global help.autocorrect 1\n```\n\n### Reuse recorded resolution, record and reuse previous conflicts resolutions.\n```sh\ngit config --global rerere.enabled 1\n```\n\n### Remove entry in the global config.\n```sh\ngit config --global --unset \u003Centry-name>\n```\n\n### Ignore file mode changes on commits\n```sh\ngit config core.fileMode false\n```\n\n### Turn off git colored terminal output\n```sh\ngit config --global color.ui false\n```\n\n### Specific color settings\n```sh\ngit config --global \u003Cspecific command e.g branch, diff> \u003Ctrue, false or always>\n```\n\n### Alias: git undo\n```sh\ngit config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'\n```\n\n### Edit [local\u002Fglobal] git config\n```sh\ngit config [--global] --edit\n```\n\n### List all git aliases\n```sh\ngit config -l | grep alias | sed 's\u002F^alias\\.\u002F\u002Fg'\n```\n**Alternatives:**\n```sh\ngit config -l | grep alias | cut -d '.' -f 2\n```\n\n### Use SSH instead of HTTPs for remotes\n```sh\ngit config --global url.'git@github.com:'.insteadOf 'https:\u002F\u002Fgithub.com\u002F'\n```\n\n### Prevent auto replacing LF with CRLF\n```sh\ngit config --global core.autocrlf false\n```\n\n### Edit config for each level\n```sh\ngit config --edit --system\n\ngit config --edit --global\n\ngit config --edit --local\n```\n\n## Stashing\n\n### Saving current state of tracked files without committing\n```sh\ngit stash\n```\n**Alternatives:**\n```sh\ngit stash push\n```\n\n### Saving current state of unstaged changes to tracked files\n```sh\ngit stash -k\n```\n**Alternatives:**\n```sh\ngit stash --keep-index\n```\n```sh\ngit stash push --keep-index\n```\n\n### Saving current state including untracked files\n```sh\ngit stash -u\n```\n**Alternatives:**\n```sh\ngit stash push -u\n```\n```sh\ngit stash push --include-untracked\n```\n\n### Saving current state with message\n```sh\ngit stash push -m \u003Cmessage>\n```\n**Alternatives:**\n```sh\ngit stash push --message \u003Cmessage>\n```\n\n### Saving current state of all files (ignored, untracked, and tracked)\n```sh\ngit stash -a\n```\n**Alternatives:**\n```sh\ngit stash --all\n```\n```sh\ngit stash push --all\n```\n\n### Show list of all saved stashes\n```sh\ngit stash list\n```\n\n### Show the contents of any stash in patch form\n```sh\ngit stash show -p \u003Cstash@{n}>\n```\n\n### Apply any stash without deleting from the stashed list\n```sh\ngit stash apply \u003Cstash@{n}>\n```\n\n### Apply last stashed state and delete it from stashed list\n```sh\ngit stash pop\n```\n**Alternatives:**\n```sh\ngit stash apply stash@{0} && git stash drop stash@{0}\n```\n\n### Delete all stored stashes\n```sh\ngit stash clear\n```\n**Alternatives:**\n```sh\ngit stash drop \u003Cstash@{n}>\n```\n\n## Submodules and Subtrees\n\n### Update all the submodules\n```sh\ngit submodule foreach git pull\n```\n**Alternatives:**\n```sh\ngit submodule update --init --recursive\n```\n```sh\ngit submodule update --remote\n```\n\n### Deploying git tracked subfolder to gh-pages\n```sh\ngit subtree push --prefix subfolder_name origin gh-pages\n```\n**Alternatives:**\n```sh\ngit subtree push --prefix subfolder_name origin branch_name\n```\n\n### Adding a project to repo using subtree\n```sh\ngit subtree add --prefix=\u003Cdirectory_name>\u002F\u003Cproject_name> --squash git@github.com:\u003Cusername>\u002F\u003Cproject_name>.git master\n```\n\n### Get latest changes in your repo for a linked project using subtree\n```sh\ngit subtree pull --prefix=\u003Cdirectory_name>\u002F\u003Cproject_name> --squash git@github.com:\u003Cusername>\u002F\u003Cproject_name>.git master\n```\n\n## Tagging\n\n### Create local tag\n```sh\ngit tag \u003Ctag-name>\n```\n\n### Delete local tag\n```sh\ngit tag -d \u003Ctag-name>\n```\n\n## Undoing Changes\n\n### Sync with remote, overwrite local changes\n```sh\ngit fetch origin && git reset --hard origin\u002Fmaster && git clean -f -d\n```\n\n### Git reset first commit\n```sh\ngit update-ref -d HEAD\n```\n\n### Reset: preserve uncommitted local changes\n```sh\ngit reset --keep \u003Ccommit>\n```\n\n### Revert: Undo a commit by creating a new commit\n```sh\ngit revert \u003Ccommit-ish>\n```\n\n### Reset: Discard commits, advised for private branch\n```sh\ngit reset \u003Ccommit-ish>\n```\n\n### Before deleting untracked files\u002Fdirectory, do a dry run to get the list of these files\u002Fdirectories\n```sh\ngit clean -n\n```\n\n### Forcefully remove untracked files\n```sh\ngit clean -f\n```\n\n### Forcefully remove untracked directory\n```sh\ngit clean -f -d\n```\n\n### Undo assume-unchanged.\n```sh\ngit update-index --no-assume-unchanged \u003Cfile_name>\n```\n\n### Clean the files from `.gitignore`.\n```sh\ngit clean -X -f\n```\n\n### Dry run. (any command that supports dry-run flag should do.)\n```sh\ngit clean -fd --dry-run\n```\n\n### Unstaging Staged file\n```sh\ngit reset HEAD \u003Cfile-name>\n```\n\n### Revert: Reverting an entire merge\n```sh\ngit revert -m 1 \u003Ccommit-ish>\n```\n\n### Restore file (modern alternative to reset\u002Fcheckout --)\n```sh\ngit restore \u003Cfile-name>\n```\n**Alternatives:**\n```sh\ngit restore --staged \u003Cfile-name>\n```\n","git-tips\u002Ftips 是一个收集了最常用 Git 技巧和窍门的项目。该项目以 JavaScript 编写，提供了一系列实用的命令行操作指南，帮助开发者更高效地使用 Git 进行版本控制。它不仅涵盖了基本操作如快速切换分支、删除远程分支等，还包含了一些高级功能，例如从 stash 中提取单个文件、修改历史提交而不改变提交信息等。此外，通过 git-tip CLI 工具或 Docker 容器，用户可以更加便捷地应用这些技巧。此项目非常适合需要频繁使用 Git 的软件开发人员以及希望提高 Git 使用效率的技术团队。","2026-06-11 02:52:33","top_language"]