{"id":24557543,"url":"https://github.com/huang-x-h/git-bonus","last_synced_at":"2026-05-22T14:06:05.824Z","repository":{"id":70319539,"uuid":"90816433","full_name":"huang-x-h/git-bonus","owner":"huang-x-h","description":"Git command colletion","archived":false,"fork":false,"pushed_at":"2019-08-17T09:09:59.000Z","size":14,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T05:20:02.556Z","etag":null,"topics":["command","git","tricks"],"latest_commit_sha":null,"homepage":null,"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/huang-x-h.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2017-05-10T03:21:43.000Z","updated_at":"2023-03-08T04:16:29.000Z","dependencies_parsed_at":"2023-02-28T05:30:33.030Z","dependency_job_id":null,"html_url":"https://github.com/huang-x-h/git-bonus","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huang-x-h%2Fgit-bonus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huang-x-h%2Fgit-bonus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huang-x-h%2Fgit-bonus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huang-x-h%2Fgit-bonus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huang-x-h","download_url":"https://codeload.github.com/huang-x-h/git-bonus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243910767,"owners_count":20367546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["command","git","tricks"],"created_at":"2025-01-23T05:17:43.645Z","updated_at":"2026-05-22T14:06:05.710Z","avatar_url":"https://github.com/huang-x-h.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git bonus\n\n\u003e Collection of git commands\n\n\u003c!-- inject:toc --\u003e\n* [Clone a single branch in git](#clone-a-single-branch-in-git)\n* [Compare two revisions of a file](#compare-two-revisions-of-a-file)\n* [Compare current staged file against the repository](#compare-current-staged-file-against-the-repository)\n* [Compare current unstaged file against the repository](#compare-current-unstaged-file-against-the-repository)\n* [Delete a branch on a remote repository](#delete-a-branch-on-a-remote-repository)\n* [Checkout a branch on a remote repository](#checkout-a-branch-on-a-remote-repository)\n* [Undo the last commit, leaving changes in the the index](#undo-the-last-commit,-leaving-changes-in-the-the-index)\n* [Discard all local changes in your working directory](#discard-all-local-changes-in-your-working-directory)\n* [Undo git add before commit](#undo-git-add-before-commit)\n* [Local branch look identical to remote branch](#local-branch-look-identical-to-remote-branch)\n* [Caching you HTTPS password in git](#caching-you-https-password-in-git)\n* [Commit case-sensitive only filename changes in git](#commit-case-sensitive-only-filename-changes-in-git)\n* [Squash Multiple Commits](#squash-multiple-commits)\n* [Stash Uncommitted Changes](#stash-uncommitted-changes)\n* [Who changed what and when in \u003cfile\u003e](#who-changed-what-and-when-in-\u003cfile\u003e)\n* [Create branch without any parents](#create-branch-without-any-parents)\n* [Delete local branches that have been removed from remote on fetch/pull](#delete-local-branches-that-have-been-removed-from-remote-on-fetch/pull)\n* [Enable Git's autosquash feature by default](#enable-git's-autosquash-feature-by-default)\n* [Quickly checkout the previous branch you were on](#quickly-checkout-the-previous-branch-you-were-on)\n* [Delete local branches which have already been merged into master](#delete-local-branches-which-have-already-been-merged-into-master)\n* [Want to change the commit message](#want-to-change-the-commit-message)\n* [Add files to the previous commit](#add-files-to-the-previous-commit)\n* [To push a single tag or all tags](#to-push-a-single-tag-or-all-tags)\n* [Count number of lines in a git repository](#count-number-of-lines-in-a-git-repository)\n* [Count number of lines changed between two commit](#count-number-of-lines-changed-between-two-commit)\n* [How to remove a submodule](#how-to-remove-a-submodule)\n\u003c!-- endinject --\u003e\n\u003c!-- inject:content --\u003e\n## Clone a single branch in git\n```sh\ngit clone user@git-server:project_name.git -b branch_name /some/folder\n```\n## Compare two revisions of a file\n```sh\ngit diff \u003ccommit1\u003e \u003ccommit2\u003e \u003cfile_name\u003e\n```\n## Compare current staged file against the repository\n```sh\ngit diff --staged \u003cfile_name\u003e\n```\n## Compare current unstaged file against the repository\n```sh\ngit diff \u003cfile_name\u003e\n```\n## Delete a branch on a remote repository\n```sh\ngit push origin :mybranchname\n```\n## Checkout a branch on a remote repository\n```sh\ngit checkout -b mybranchname origin/mybranchname\n```\n## Undo the last commit, leaving changes in the the index\n```sh\ngit reset --soft HEAD^\n```\n## Discard all local changes in your working directory\n```sh\ngit reset --hard HEAD\n```\n## Undo git add before commit\n```sh\ngit reset \u003cfile\u003e\n```\n## Local branch look identical to remote branch\n```sh\ngit reset --hard origin/master\n```\n## Caching you HTTPS password in git\n```sh\ngit config --global credential.helper store\n```\n## Commit case-sensitive only filename changes in git\n```sh\ngit mv -f OldFileNameCase newfilenamecase\n```\n## Squash Multiple Commits\n```sh\ngit rebase -i HEAD~2\n```\n## Stash Uncommitted Changes\n```sh\ngit stash\n```\n## Who changed what and when in \u003cfile\u003e\n```sh\ngit blame \u003cfile\u003e\n```\n## Create branch without any parents\n```sh\ngit checkout --orphan mybranchname\n```\n## Delete local branches that have been removed from remote on fetch/pull\n```sh\ngit config --global fetch.prune true\n```\n## Enable Git's autosquash feature by default\n```sh\ngit config --global rebase.autosquash true\n```\n## Quickly checkout the previous branch you were on\n```sh\ngit checkout -\n```\n## Delete local branches which have already been merged into master\n```sh\ngit branch --merged master | grep -v \"master\" | xargs -n 1 git branch -d\n```\n## Want to change the commit message\n```sh\ngit commit --amend -m \"New commit message\"\n```\n## Add files to the previous commit\n```sh\ngit add file\ngit commit --amend --no-edit\n```\n## To push a single tag or all tags\n```sh\ngit push origin \u003ctag_name\u003e\ngit push --tags\n```\n## Count number of lines in a git repository\n```sh\ngit ls-files | xargs cat | wc -l\n```\n## Count number of lines changed between two commit\n```sh\ngit diff --shortstat \u003ccommit1\u003e \u003ccommit2\u003e\n```\n## How to remove a submodule\n```sh\n1.Delete the relevant section from the .gitmodules file\n  rm -f .gitmodules\n2.Stage the .gitmodules changes\n  git add .gitmodules\n3.Delete the relevant section from .git/config\n  rm -f .git/config\n4.Remove the submodule files from the working tree and index\n  git rm --cached path_to_submodule\n5.Remove the submodule's .git directory\n  rm -rf .git/modules/path_to_submodule\n6.Commit the changes\n  git commit -m \"Removed submodule \u003cname\u003e\"\n```\n\u003c!-- endinject --\u003e\n\n\n# Related\n\n\u003e git-tips https://github.com/git-tips/tips\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuang-x-h%2Fgit-bonus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuang-x-h%2Fgit-bonus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuang-x-h%2Fgit-bonus/lists"}