{"id":47091900,"url":"https://git-tips.github.io/tips/","last_synced_at":"2026-03-26T15:00:57.588Z","repository":{"id":38271695,"uuid":"39122628","full_name":"git-tips/tips","owner":"git-tips","description":"Most commonly used git tips and tricks.","archived":false,"fork":false,"pushed_at":"2024-10-23T21:26:23.000Z","size":421,"stargazers_count":21696,"open_issues_count":34,"forks_count":1717,"subscribers_count":545,"default_branch":"master","last_synced_at":"2026-03-06T17:32:09.309Z","etag":null,"topics":["git","tips","tips-and-tricks"],"latest_commit_sha":null,"homepage":"http://git.io/git-tips","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/git-tips.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-15T07:24:48.000Z","updated_at":"2026-03-06T03:52:54.000Z","dependencies_parsed_at":"2022-07-14T10:21:38.905Z","dependency_job_id":"3445c367-960b-4e9d-9fbd-884f926b0b3d","html_url":"https://github.com/git-tips/tips","commit_stats":{"total_commits":263,"total_committers":88,"mean_commits":"2.9886363636363638","dds":0.688212927756654,"last_synced_commit":"a3bc5fc82f6599bc923dc18573223ec9b53dc932"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/git-tips/tips","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-tips%2Ftips","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-tips%2Ftips/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-tips%2Ftips/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-tips%2Ftips/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/git-tips","download_url":"https://codeload.github.com/git-tips/tips/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-tips%2Ftips/sbom","scorecard":{"id":427879,"data":{"date":"2025-08-11","repo":{"name":"github.com/git-tips/tips","commit":"a3bc5fc82f6599bc923dc18573223ec9b53dc932"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":8,"reason":"Found 13/15 approved changesets -- score normalized to 8","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-cwcx-rxgc-cmw3"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 28 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T02:38:25.959Z","repository_id":38271695,"created_at":"2025-08-19T02:38:25.960Z","updated_at":"2025-08-19T02:38:25.960Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30972995,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-26T14:13:19.610Z","status":"ssl_error","status_checked_at":"2026-03-26T14:12:43.279Z","response_time":114,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","tips","tips-and-tricks"],"created_at":"2026-03-12T11:00:28.343Z","updated_at":"2026-03-26T15:00:57.581Z","avatar_url":"https://github.com/git-tips.png","language":"JavaScript","readme":"## git-tips\n\u003e Collection of `git-tips`, want to add your tips? Checkout [contributing.md](./contributing.md)\n\n[English](http://git.io/git-tips) | [中文](https://github.com/521xueweihan/git-tips) | [Русский](https://github.com/Imangazaliev/git-tips) | [한국어](https://github.com/mingrammer/git-tips) | [Tiếng Việt](https://github.com/hprobotic/git-tips) | [日本語](https://github.com/isotai/git-tips) | [नेपाली](https://github.com/amarduwal/git-tips) | [Polski](https://github.com/mbiesiad/tips) | [فارسی](https://github.com/javadnikbakht/git-tips)\n\n### __Tools:__\n\n* [git-tip](https://www.npmjs.com/package/git-tip) - A handy CLI to make optimum use of these tips. ([Here in Docker container](https://github.com/djoudi5/docker-git-tip))\n\n📖 **[Read the interactive GitBook documentation here!](https://git-tips.github.io/tips/)**\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/global] 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/directory, do a dry run to get the list of these files/directories](#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/checkout --)](#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\u003e\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\u003e\n```\n**Alternatives:**\n```sh\ngit push origin :\u003cremote_branchname\u003e\n```\n```sh\ngit branch -dr \u003cremote/branch\u003e\n```\n\n### Delete remote tag\n```sh\ngit push origin :refs/tags/\u003ctag-name\u003e\n```\n\n### Undo local changes with the content in index(staging)\n```sh\ngit checkout -- \u003cfile_name\u003e\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\u003e'\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\u003e \u0026\u0026 git cherry-pick \u003ccommit-ish\u003e\n```\n\n### Grab a single file from a stash\n```sh\ngit checkout \u003cstash@{n}\u003e -- \u003cfile_path\u003e\n```\n**Alternatives:**\n```sh\ngit checkout stash@{0} -- \u003cfile_path\u003e\n```\n\n### Create new working tree from a repository (git 2.5)\n```sh\ngit worktree add -b \u003cbranch-name\u003e \u003cpath\u003e \u003cstart-point\u003e\n```\n\n### Create new working tree from HEAD state\n```sh\ngit worktree add --detach \u003cpath\u003e 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\u003e\n```\n\n### Modify previous commit without modifying the commit message\n```sh\ngit add --all \u0026\u0026 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\u003e -b \u003cbranch-name\u003e\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/\u003cid\u003e/head:\u003cbranch-name\u003e\n```\n**Alternatives:**\n```sh\ngit pull origin pull/\u003cid\u003e/head:\u003cbranch-name\u003e\n```\n\n### Restore deleted file.\n```sh\ngit checkout \u003cdeleting_commit\u003e -- \u003cfile_path\u003e\n```\n\n### Restore file to a specific commit-hash\n```sh\ngit checkout \u003ccommit-ish\u003e -- \u003cfile_path\u003e\n```\n\n### Marks your commit as a fix of a previous commit.\n```sh\ngit commit --fixup \u003cSHA-1\u003e\n```\n\n### Skip staging area during commit.\n```sh\ngit commit --only \u003cfile_path\u003e\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\u003e\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\u003e --single-branch https://github.com/user/repo.git\n```\n\n### Create and switch new branch\n```sh\ngit checkout -b \u003cbranch-name\u003e\n```\n**Alternatives:**\n```sh\ngit branch \u003cbranch-name\u003e \u0026\u0026 git checkout \u003cbranch-name\u003e\n```\n```sh\ngit switch -c \u003cbranch-name\u003e\n```\n\n### Show all local branches ordered by recent commits\n```sh\ngit for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/\n```\n\n### Clone a shallow copy of a repository\n```sh\ngit clone https://github.com/user/repo.git --depth 1\n```\n\n### Force push to Remote Repository\n```sh\ngit push -f \u003cremote-name\u003e \u003cbranch-name\u003e\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\u003e \u003cbranch-name\u003e\n```\n\n### Number of commits in a branch\n```sh\ngit rev-list --count \u003cbranch-name\u003e\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\u003e/.git format-patch -k -1 --stdout \u003cSHA1\u003e | git am -3 -k\n```\n\n### Specific fetch reference\n```sh\ngit fetch origin master:refs/remotes/origin/mymaster\n```\n\n### Generates a summary of pending changes\n```sh\ngit request-pull v1.0 https://git.ko.xz/project 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\u003e\n```\n\n### Update a submodule to the latest commit\n```sh\ncd \u003cpath-to-submodule\u003e\ngit pull origin \u003cbranch\u003e\ncd \u003croot-of-your-main-project\u003e\ngit add \u003cpath-to-submodule\u003e\ngit commit -m \"submodule updated\"\n```\n\n### Duplicating a repository\n```sh\ngit clone --bare https://github.com/exampleuser/old-repository.git\n\ngit push --mirror https://github.com/exampleuser/new-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/mybranch\n```\n\n### Delete local branch\n```sh\ngit branch -d \u003clocal_branchname\u003e\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\u003e\n```\n**Alternatives:**\n```sh\ngit branch --contains \u003ccommit-ish\u003e\n```\n\n### Rename a branch\n```sh\ngit branch -m \u003cnew-branch-name\u003e\n```\n**Alternatives:**\n```sh\ngit branch -m [\u003cold-branch-name\u003e] \u003cnew-branch-name\u003e\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\u003e \u003cbranch-name\u003e\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 \u0026\u0026 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\u003e\n```\n**Alternatives:**\n```sh\ngit switch -c \u003cnew-branch-name\u003e\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\u003e'\n```\n\n### Show changes over time for specific file\n```sh\ngit log -p \u003cfile_name\u003e\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\u003e\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\u003e] \u003ccommit1\u003e \u003ccommit2\u003e \u003cpath\u003e\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\u003e\n```\n**Alternatives:**\n```sh\ngit log -n \u003cn\u003e\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\u003e:\u003cfile_name\u003e\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\u003e\n```\n\n### Search Commit log across all branches for given text\n```sh\ngit log --all --grep='\u003cgiven-text\u003e'\n```\n\n### Get first commit in a branch (from master)\n```sh\ngit log --oneline master..\u003cbranch-name\u003e | tail -1\n```\n**Alternatives:**\n```sh\ngit log --reverse master..\u003cbranch-name\u003e | 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\u003e\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\u003e,\u003cend\u003e\n```\n\n### Show a Git logical variable.\n```sh\ngit var -l | \u003cvariable\u003e\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 \u0026\u0026 git checkout master \u0026\u0026 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\u003e \u003cother-branch-name\u003e\n```\n\n### Change a branch base\n```sh\ngit rebase --onto \u003cnew_base\u003e \u003cold_base\u003e\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\u003e\n```\n**Alternatives:**\n```sh\ngit rm --cached -r \u003cdirectory_path\u003e\n```\n\n### Don’t consider changes for tracked file.\n```sh\ngit update-index --assume-unchanged \u003cfile_name\u003e\n```\n\n### Check if the change was a part of a release.\n```sh\ngit name-rev --name-only \u003cSHA-1\u003e\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\u003e] [--port=\u003cport\u003e] [--browser=\u003cbrowser\u003e]\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\u003e] \u003cfile|directory\u003e…\n\ngit send-email [\u003coptions\u003e] \u003cformat-patch options\u003e\n```\n\n## Remotes\n\n### Changing a remote's URL\n```sh\ngit remote set-url origin \u003cURL\u003e\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\u003e \u003cremote-url\u003e\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://git.kernel.org/pub/scm/git/git.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\u003e' --prune-empty --tag-name-filter cat -- --all \u0026\u0026 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://git.io/vfhol \u003e ~/.git-completion.bash \u0026\u0026 echo '[ -f ~/.git-completion.bash ] \u0026\u0026 . ~/.git-completion.bash' \u003e\u003e ~/.bashrc\n```\n\n### Git Aliases\n```sh\ngit config --global alias.\u003chandle\u003e \u003ccommand\u003e \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\u003e\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\u003e \u003ctrue, false or always\u003e\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/global] git config\n```sh\ngit config [--global] --edit\n```\n\n### List all git aliases\n```sh\ngit config -l | grep alias | sed 's/^alias\\.//g'\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://github.com/'\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\u003e\n```\n**Alternatives:**\n```sh\ngit stash push --message \u003cmessage\u003e\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}\u003e\n```\n\n### Apply any stash without deleting from the stashed list\n```sh\ngit stash apply \u003cstash@{n}\u003e\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} \u0026\u0026 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}\u003e\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\u003e/\u003cproject_name\u003e --squash git@github.com:\u003cusername\u003e/\u003cproject_name\u003e.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\u003e/\u003cproject_name\u003e --squash git@github.com:\u003cusername\u003e/\u003cproject_name\u003e.git master\n```\n\n## Tagging\n\n### Create local tag\n```sh\ngit tag \u003ctag-name\u003e\n```\n\n### Delete local tag\n```sh\ngit tag -d \u003ctag-name\u003e\n```\n\n## Undoing Changes\n\n### Sync with remote, overwrite local changes\n```sh\ngit fetch origin \u0026\u0026 git reset --hard origin/master \u0026\u0026 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\u003e\n```\n\n### Revert: Undo a commit by creating a new commit\n```sh\ngit revert \u003ccommit-ish\u003e\n```\n\n### Reset: Discard commits, advised for private branch\n```sh\ngit reset \u003ccommit-ish\u003e\n```\n\n### Before deleting untracked files/directory, do a dry run to get the list of these files/directories\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\u003e\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\u003e\n```\n\n### Revert: Reverting an entire merge\n```sh\ngit revert -m 1 \u003ccommit-ish\u003e\n```\n\n### Restore file (modern alternative to reset/checkout --)\n```sh\ngit restore \u003cfile-name\u003e\n```\n**Alternatives:**\n```sh\ngit restore --staged \u003cfile-name\u003e\n```\n","funding_links":[],"categories":["git-tips"],"sub_categories":["__Tools:__"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/git-tips.github.io%2Ftips%2F","html_url":"https://awesome.ecosyste.ms/projects/git-tips.github.io%2Ftips%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/git-tips.github.io%2Ftips%2F/lists"}