├── .doxie.render.js ├── .doxie.render.toc.js ├── .gitignore ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── contributing.md ├── package-lock.json ├── package.json └── tips.json /.doxie.render.js: -------------------------------------------------------------------------------- 1 | function escapeStr(str) { 2 | return str 3 | .replace(/\"/g, '\\"') 4 | .replace(/\n/g, '\\n'); 5 | } 6 | 7 | var render = function(data) { 8 | var data = data.data; 9 | 10 | var tips = [ 11 | '## ' + data.title, 12 | '```sh', 13 | data.tip, 14 | '```', 15 | '\n' 16 | ]; 17 | Array.isArray(data.alternatives) && tips.push(['__Alternatives:__']) && 18 | data.alternatives.map(function(alternative){ 19 | tips = tips.concat(['```sh',alternative,'```','\n']) 20 | }); 21 | return tips.join('\n'); 22 | }; 23 | 24 | module.exports = render; 25 | -------------------------------------------------------------------------------- /.doxie.render.toc.js: -------------------------------------------------------------------------------- 1 | // from https://gist.github.com/mathewbyrne/1280286 2 | slugify = function(text){ 3 | return text.toString().toLowerCase() 4 | .replace(/\s+/g, '-') // Replace spaces with - 5 | .replace(/[^\w\-]+/g, '') // Remove all non-word chars 6 | .replace(/\-\-+/g, '-') // Replace multiple - with single - 7 | .replace(/^-+/, '') // Trim - from start of text 8 | .replace(/-+$/, ''); // Trim - from end of text 9 | } 10 | 11 | var render = function(data) { 12 | var data = data.data; 13 | 14 | var out = '* [' + data.title + '](#' + slugify(data.title) + ')\n'; 15 | 16 | return out; 17 | }; 18 | 19 | module.exports = render; 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | npm-debug.log 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "eslint.enable": false, 3 | "vsicons.presets.angular": false 4 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at hemanth.hm@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Hemanth.HM 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## git-tips 2 | > Collection of `git-tips`, want to add your tips? Checkout [contributing.md](./contributing.md) 3 | 4 | [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) 5 | 6 | ### __Tools:__ 7 | 8 | * [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)) 9 | 10 | P.S: All these commands are tested on `git version 2.7.4 (Apple Git-66)`. 11 | 12 | 13 | 14 | * [Everyday Git in twenty commands or so](#everyday-git-in-twenty-commands-or-so) 15 | * [Show helpful guides that come with Git](#show-helpful-guides-that-come-with-git) 16 | * [Search change by content](#search-change-by-content) 17 | * [Show changes over time for specific file](#show-changes-over-time-for-specific-file) 18 | * [Remove sensitive data from history, after a push](#remove-sensitive-data-from-history-after-a-push) 19 | * [Sync with remote, overwrite local changes](#sync-with-remote-overwrite-local-changes) 20 | * [List of all files till a commit](#list-of-all-files-till-a-commit) 21 | * [Git reset first commit](#git-reset-first-commit) 22 | * [Reset: preserve uncommitted local changes](#reset-preserve-uncommitted-local-changes) 23 | * [List all the conflicted files](#list-all-the-conflicted-files) 24 | * [List of all files changed in a commit](#list-of-all-files-changed-in-a-commit) 25 | * [Unstaged changes since last commit](#unstaged-changes-since-last-commit) 26 | * [Changes staged for commit](#changes-staged-for-commit) 27 | * [Show both staged and unstaged changes](#show-both-staged-and-unstaged-changes) 28 | * [List all branches that are already merged into master](#list-all-branches-that-are-already-merged-into-master) 29 | * [Quickly switch to the previous branch](#quickly-switch-to-the-previous-branch) 30 | * [Remove branches that have already been merged with master](#remove-branches-that-have-already-been-merged-with-master) 31 | * [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) 32 | * [Track upstream branch](#track-upstream-branch) 33 | * [Delete local branch](#delete-local-branch) 34 | * [Delete remote branch](#delete-remote-branch) 35 | * [Create local tag](#create-local-tag) 36 | * [Delete local tag](#delete-local-tag) 37 | * [Delete remote tag](#delete-remote-tag) 38 | * [Undo local changes with the last content in head](#undo-local-changes-with-the-last-content-in-head) 39 | * [Revert: Undo a commit by creating a new commit](#revert-undo-a-commit-by-creating-a-new-commit) 40 | * [Reset: Discard commits, advised for private branch](#reset-discard-commits-advised-for-private-branch) 41 | * [Reword the previous commit message](#reword-the-previous-commit-message) 42 | * [See commit history for just the current branch](#see-commit-history-for-just-the-current-branch) 43 | * [Amend author.](#amend-author) 44 | * [Reset author, after author has been changed in the global config.](#reset-author-after-author-has-been-changed-in-the-global-config) 45 | * [Changing a remote's URL](#changing-a-remotes-url) 46 | * [Get list of all remote references](#get-list-of-all-remote-references) 47 | * [Get list of all local and remote branches](#get-list-of-all-local-and-remote-branches) 48 | * [Get only remote branches](#get-only-remote-branches) 49 | * [Stage parts of a changed file, instead of the entire file](#stage-parts-of-a-changed-file-instead-of-the-entire-file) 50 | * [Get git bash completion](#get-git-bash-completion) 51 | * [What changed since two weeks?](#what-changed-since-two-weeks) 52 | * [See all commits made since forking from master](#see-all-commits-made-since-forking-from-master) 53 | * [Pick commits across branches using cherry-pick](#pick-commits-across-branches-using-cherry-pick) 54 | * [Find out branches containing commit-hash](#find-out-branches-containing-commit-hash) 55 | * [Git Aliases](#git-aliases) 56 | * [Saving current state of tracked files without commiting](#saving-current-state-of-tracked-files-without-commiting) 57 | * [Saving current state of unstaged changes to tracked files](#saving-current-state-of-unstaged-changes-to-tracked-files) 58 | * [Saving current state including untracked files](#saving-current-state-including-untracked-files) 59 | * [Saving current state with message](#saving-current-state-with-message) 60 | * [Saving current state of all files (ignored, untracked, and tracked)](#saving-current-state-of-all-files-ignored-untracked-and-tracked) 61 | * [Show list of all saved stashes](#show-list-of-all-saved-stashes) 62 | * [Show the contents of any stash in patch form](#show-the-contents-of-any-stash-in-patch-form) 63 | * [Apply any stash without deleting from the stashed list](#apply-any-stash-without-deleting-from-the-stashed-list) 64 | * [Apply last stashed state and delete it from stashed list](#apply-last-stashed-state-and-delete-it-from-stashed-list) 65 | * [Delete all stored stashes](#delete-all-stored-stashes) 66 | * [Grab a single file from a stash](#grab-a-single-file-from-a-stash) 67 | * [Show all tracked files](#show-all-tracked-files) 68 | * [Show all untracked files](#show-all-untracked-files) 69 | * [Show all ignored files](#show-all-ignored-files) 70 | * [Create new working tree from a repository (git 2.5)](#create-new-working-tree-from-a-repository-git-25) 71 | * [Create new working tree from HEAD state](#create-new-working-tree-from-head-state) 72 | * [Untrack files without deleting](#untrack-files-without-deleting) 73 | * [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) 74 | * [Forcefully remove untracked files](#forcefully-remove-untracked-files) 75 | * [Forcefully remove untracked directory](#forcefully-remove-untracked-directory) 76 | * [Update all the submodules](#update-all-the-submodules) 77 | * [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) 78 | * [Rename a branch](#rename-a-branch) 79 | * [Rebases 'feature' to 'master' and merges it in to master ](#rebases-feature-to-master-and-merges-it-in-to-master) 80 | * [Archive the `master` branch](#archive-the-master-branch) 81 | * [Modify previous commit without modifying the commit message](#modify-previous-commit-without-modifying-the-commit-message) 82 | * [Prunes references to remove branches that have been deleted in the remote.](#prunes-references-to-remove-branches-that-have-been-deleted-in-the-remote) 83 | * [Delete local branches that has been squash and merged in the remote.](#delete-local-branches-that-has-been-squash-and-merged-in-the-remote) 84 | * [Retrieve the commit hash of the initial revision.](#retrieve-the-commit-hash-of-the-initial-revision) 85 | * [Visualize the version tree.](#visualize-the-version-tree) 86 | * [Visualize the tree including commits that are only referenced from reflogs](#visualize-the-tree-including-commits-that-are-only-referenced-from-reflogs) 87 | * [Deploying git tracked subfolder to gh-pages](#deploying-git-tracked-subfolder-to-gh-pages) 88 | * [Adding a project to repo using subtree](#adding-a-project-to-repo-using-subtree) 89 | * [Get latest changes in your repo for a linked project using subtree](#get-latest-changes-in-your-repo-for-a-linked-project-using-subtree) 90 | * [Export a branch with history to a file.](#export-a-branch-with-history-to-a-file) 91 | * [Import from a bundle](#import-from-a-bundle) 92 | * [Get the name of current branch.](#get-the-name-of-current-branch) 93 | * [Ignore one file on commit (e.g. Changelog).](#ignore-one-file-on-commit-eg-changelog) 94 | * [Stash changes before rebasing](#stash-changes-before-rebasing) 95 | * [Fetch pull request by ID to a local branch](#fetch-pull-request-by-id-to-a-local-branch) 96 | * [Show the most recent tag on the current branch.](#show-the-most-recent-tag-on-the-current-branch) 97 | * [Show inline word diff.](#show-inline-word-diff) 98 | * [Show changes using common diff tools.](#show-changes-using-common-diff-tools) 99 | * [Don’t consider changes for tracked file.](#dont-consider-changes-for-tracked-file) 100 | * [Undo assume-unchanged.](#undo-assume-unchanged) 101 | * [Clean the files from `.gitignore`.](#clean-the-files-from-gitignore) 102 | * [Restore deleted file.](#restore-deleted-file) 103 | * [Restore file to a specific commit-hash](#restore-file-to-a-specific-commit-hash) 104 | * [Always rebase instead of merge on pull.](#always-rebase-instead-of-merge-on-pull) 105 | * [List all the alias and configs.](#list-all-the-alias-and-configs) 106 | * [Make git case sensitive.](#make-git-case-sensitive) 107 | * [Add custom editors.](#add-custom-editors) 108 | * [Auto correct typos.](#auto-correct-typos) 109 | * [Check if the change was a part of a release.](#check-if-the-change-was-a-part-of-a-release) 110 | * [Dry run. (any command that supports dry-run flag should do.)](#dry-run-any-command-that-supports-dry-run-flag-should-do) 111 | * [Marks your commit as a fix of a previous commit.](#marks-your-commit-as-a-fix-of-a-previous-commit) 112 | * [Squash fixup commits normal commits.](#squash-fixup-commits-normal-commits) 113 | * [Skip staging area during commit.](#skip-staging-area-during-commit) 114 | * [Interactive staging.](#interactive-staging) 115 | * [List ignored files.](#list-ignored-files) 116 | * [Status of ignored files.](#status-of-ignored-files) 117 | * [Commits in Branch1 that are not in Branch2](#commits-in-branch1-that-are-not-in-branch2) 118 | * [List n last commits](#list-n-last-commits) 119 | * [Reuse recorded resolution, record and reuse previous conflicts resolutions.](#reuse-recorded-resolution-record-and-reuse-previous-conflicts-resolutions) 120 | * [Open all conflicted files in an editor.](#open-all-conflicted-files-in-an-editor) 121 | * [Count unpacked number of objects and their disk consumption.](#count-unpacked-number-of-objects-and-their-disk-consumption) 122 | * [Prune all unreachable objects from the object database.](#prune-all-unreachable-objects-from-the-object-database) 123 | * [Instantly browse your working repository in gitweb.](#instantly-browse-your-working-repository-in-gitweb) 124 | * [View the GPG signatures in the commit log](#view-the-gpg-signatures-in-the-commit-log) 125 | * [Remove entry in the global config.](#remove-entry-in-the-global-config) 126 | * [Checkout a new branch without any history](#checkout-a-new-branch-without-any-history) 127 | * [Extract file from another branch.](#extract-file-from-another-branch) 128 | * [List only the root and merge commits.](#list-only-the-root-and-merge-commits) 129 | * [Change previous two commits with an interactive rebase.](#change-previous-two-commits-with-an-interactive-rebase) 130 | * [List all branch is WIP](#list-all-branch-is-wip) 131 | * [Find guilty with binary search](#find-guilty-with-binary-search) 132 | * [Bypass pre-commit and commit-msg githooks](#bypass-pre-commit-and-commit-msg-githooks) 133 | * [List commits and changes to a specific file (even through renaming)](#list-commits-and-changes-to-a-specific-file-even-through-renaming) 134 | * [Clone a single branch](#clone-a-single-branch) 135 | * [Create and switch new branch](#create-and-switch-new-branch) 136 | * [Ignore file mode changes on commits](#ignore-file-mode-changes-on-commits) 137 | * [Turn off git colored terminal output](#turn-off-git-colored-terminal-output) 138 | * [Specific color settings](#specific-color-settings) 139 | * [Show all local branches ordered by recent commits](#show-all-local-branches-ordered-by-recent-commits) 140 | * [Find lines matching the pattern (regex or string) in tracked files](#find-lines-matching-the-pattern-regex-or-string-in-tracked-files) 141 | * [Clone a shallow copy of a repository](#clone-a-shallow-copy-of-a-repository) 142 | * [Search Commit log across all branches for given text](#search-commit-log-across-all-branches-for-given-text) 143 | * [Get first commit in a branch (from master)](#get-first-commit-in-a-branch-from-master) 144 | * [Unstaging Staged file](#unstaging-staged-file) 145 | * [Force push to Remote Repository](#force-push-to-remote-repository) 146 | * [Adding Remote name](#adding-remote-name) 147 | * [List all currently configured remotes](#list-all-currently-configured-remotes) 148 | * [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) 149 | * [Group commits by authors and title](#group-commits-by-authors-and-title) 150 | * [Forced push but still ensure you don't overwrite other's work](#forced-push-but-still-ensure-you-dont-overwrite-others-work) 151 | * [Show how many lines does an author contribute](#show-how-many-lines-does-an-author-contribute) 152 | * [Revert: Reverting an entire merge](#revert-reverting-an-entire-merge) 153 | * [Number of commits in a branch](#number-of-commits-in-a-branch) 154 | * [Alias: git undo](#alias-git-undo) 155 | * [Add object notes](#add-object-notes) 156 | * [Show all the git-notes](#show-all-the-git-notes) 157 | * [Apply commit from another repository](#apply-commit-from-another-repository) 158 | * [Specific fetch reference](#specific-fetch-reference) 159 | * [Find common ancestor of two branches](#find-common-ancestor-of-two-branches) 160 | * [List unpushed git commits](#list-unpushed-git-commits) 161 | * [Add everything, but whitespace changes](#add-everything-but-whitespace-changes) 162 | * [Edit [local/global] git config](#edit-localglobal-git-config) 163 | * [blame on certain range](#blame-on-certain-range) 164 | * [Show a Git logical variable.](#show-a-git-logical-variable) 165 | * [Preformatted patch file.](#preformatted-patch-file) 166 | * [Get the repo name.](#get-the-repo-name) 167 | * [logs between date range](#logs-between-date-range) 168 | * [Exclude author from logs](#exclude-author-from-logs) 169 | * [Generates a summary of pending changes](#generates-a-summary-of-pending-changes) 170 | * [List references in a remote repository](#list-references-in-a-remote-repository) 171 | * [Backup untracked files.](#backup-untracked-files) 172 | * [List all git aliases](#list-all-git-aliases) 173 | * [Show git status short](#show-git-status-short) 174 | * [Checkout a commit prior to a day ago](#checkout-a-commit-prior-to-a-day-ago) 175 | * [Push the current branch to the same name on the remote repository](#push-the-current-branch-to-the-same-name-on-the-remote-repository) 176 | * [Push a new local branch to remote repository and track](#push-a-new-local-branch-to-remote-repository-and-track) 177 | * [Change a branch base](#change-a-branch-base) 178 | * [Use SSH instead of HTTPs for remotes](#use-ssh-instead-of-https-for-remotes) 179 | * [Update a submodule to the latest commit](#update-a-submodule-to-the-latest-commit) 180 | * [Prevent auto replacing LF with CRLF](#prevent-auto-replacing-lf-with-crlf) 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | ## Everyday Git in twenty commands or so 189 | ```sh 190 | git help everyday 191 | ``` 192 | 193 | ## Show helpful guides that come with Git 194 | ```sh 195 | git help -g 196 | ``` 197 | 198 | ## Search change by content 199 | ```sh 200 | git log -S'' 201 | ``` 202 | 203 | ## Show changes over time for specific file 204 | ```sh 205 | git log -p 206 | ``` 207 | 208 | ## Remove sensitive data from history, after a push 209 | ```sh 210 | git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all 211 | ``` 212 | 213 | ## Sync with remote, overwrite local changes 214 | ```sh 215 | git fetch origin && git reset --hard origin/master && git clean -f -d 216 | ``` 217 | 218 | ## List of all files till a commit 219 | ```sh 220 | git ls-tree --name-only -r 221 | ``` 222 | 223 | ## Git reset first commit 224 | ```sh 225 | git update-ref -d HEAD 226 | ``` 227 | 228 | ## Reset: preserve uncommitted local changes 229 | ```sh 230 | git reset --keep 231 | ``` 232 | 233 | ## List all the conflicted files 234 | ```sh 235 | git diff --name-only --diff-filter=U 236 | ``` 237 | 238 | ## List of all files changed in a commit 239 | ```sh 240 | git diff-tree --no-commit-id --name-only -r 241 | ``` 242 | 243 | ## Unstaged changes since last commit 244 | ```sh 245 | git diff 246 | ``` 247 | 248 | ## Changes staged for commit 249 | ```sh 250 | git diff --cached 251 | ``` 252 | 253 | 254 | __Alternatives:__ 255 | ```sh 256 | git diff --staged 257 | ``` 258 | 259 | ## Show both staged and unstaged changes 260 | ```sh 261 | git diff HEAD 262 | ``` 263 | 264 | ## List all branches that are already merged into master 265 | ```sh 266 | git branch --merged master 267 | ``` 268 | 269 | ## Quickly switch to the previous branch 270 | ```sh 271 | git checkout - 272 | ``` 273 | 274 | 275 | __Alternatives:__ 276 | ```sh 277 | git checkout @{-1} 278 | ``` 279 | 280 | ## Remove branches that have already been merged with master 281 | ```sh 282 | git branch --merged master | grep -v '^\*' | xargs -n 1 git branch -d 283 | ``` 284 | 285 | 286 | __Alternatives:__ 287 | ```sh 288 | git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d # will not delete master if master is not checked out 289 | ``` 290 | 291 | ## List all branches and their upstreams, as well as last commit on branch 292 | ```sh 293 | git branch -vv 294 | ``` 295 | 296 | ## Track upstream branch 297 | ```sh 298 | git branch -u origin/mybranch 299 | ``` 300 | 301 | ## Delete local branch 302 | ```sh 303 | git branch -d 304 | ``` 305 | 306 | ## Delete remote branch 307 | ```sh 308 | git push origin --delete 309 | ``` 310 | 311 | 312 | __Alternatives:__ 313 | ```sh 314 | git push origin : 315 | ``` 316 | 317 | 318 | ```sh 319 | git branch -dr 320 | ``` 321 | 322 | ## Create local tag 323 | ```sh 324 | git tag 325 | ``` 326 | 327 | ## Delete local tag 328 | ```sh 329 | git tag -d 330 | ``` 331 | 332 | ## Delete remote tag 333 | ```sh 334 | git push origin :refs/tags/ 335 | ``` 336 | 337 | ## Undo local changes with the content in index(staging) 338 | ```sh 339 | git checkout -- 340 | ``` 341 | 342 | ## Revert: Undo a commit by creating a new commit 343 | ```sh 344 | git revert 345 | ``` 346 | 347 | ## Reset: Discard commits, advised for private branch 348 | ```sh 349 | git reset 350 | ``` 351 | 352 | ## Reword the previous commit message 353 | ```sh 354 | git commit -v --amend 355 | ``` 356 | 357 | ## See commit history for just the current branch 358 | ```sh 359 | git cherry -v master 360 | ``` 361 | 362 | ## Amend author. 363 | ```sh 364 | git commit --amend --author='Author Name ' 365 | ``` 366 | 367 | ## Reset author, after author has been changed in the global config. 368 | ```sh 369 | git commit --amend --reset-author --no-edit 370 | ``` 371 | 372 | ## Changing a remote's URL 373 | ```sh 374 | git remote set-url origin 375 | ``` 376 | 377 | ## Get list of all remote references 378 | ```sh 379 | git remote 380 | ``` 381 | 382 | 383 | __Alternatives:__ 384 | ```sh 385 | git remote show 386 | ``` 387 | 388 | ## Get list of all local and remote branches 389 | ```sh 390 | git branch -a 391 | ``` 392 | 393 | ## Get only remote branches 394 | ```sh 395 | git branch -r 396 | ``` 397 | 398 | ## Stage parts of a changed file, instead of the entire file 399 | ```sh 400 | git add -p 401 | ``` 402 | 403 | ## Get git bash completion 404 | ```sh 405 | curl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc 406 | ``` 407 | 408 | ## What changed since two weeks? 409 | ```sh 410 | git log --no-merges --raw --since='2 weeks ago' 411 | ``` 412 | 413 | 414 | __Alternatives:__ 415 | ```sh 416 | git whatchanged --since='2 weeks ago' 417 | ``` 418 | 419 | ## See all commits made since forking from master 420 | ```sh 421 | git log --no-merges --stat --reverse master.. 422 | ``` 423 | 424 | ## Pick commits across branches using cherry-pick 425 | ```sh 426 | git checkout && git cherry-pick 427 | ``` 428 | 429 | ## Find out branches containing commit-hash 430 | ```sh 431 | git branch -a --contains 432 | ``` 433 | 434 | 435 | __Alternatives:__ 436 | ```sh 437 | git branch --contains 438 | ``` 439 | 440 | ## Git Aliases 441 | ```sh 442 | git config --global alias. 443 | git config --global alias.st status 444 | ``` 445 | 446 | ## Saving current state of tracked files without commiting 447 | ```sh 448 | git stash 449 | ``` 450 | 451 | 452 | __Alternatives:__ 453 | ```sh 454 | git stash push 455 | ``` 456 | 457 | ## Saving current state of unstaged changes to tracked files 458 | ```sh 459 | git stash -k 460 | ``` 461 | 462 | 463 | __Alternatives:__ 464 | ```sh 465 | git stash --keep-index 466 | ``` 467 | 468 | 469 | ```sh 470 | git stash push --keep-index 471 | ``` 472 | 473 | ## Saving current state including untracked files 474 | ```sh 475 | git stash -u 476 | ``` 477 | 478 | 479 | __Alternatives:__ 480 | ```sh 481 | git stash push -u 482 | ``` 483 | 484 | 485 | ```sh 486 | git stash push --include-untracked 487 | ``` 488 | 489 | ## Saving current state with message 490 | ```sh 491 | git stash push -m 492 | ``` 493 | 494 | 495 | __Alternatives:__ 496 | ```sh 497 | git stash push --message 498 | ``` 499 | 500 | ## Saving current state of all files (ignored, untracked, and tracked) 501 | ```sh 502 | git stash -a 503 | ``` 504 | 505 | 506 | __Alternatives:__ 507 | ```sh 508 | git stash --all 509 | ``` 510 | 511 | 512 | ```sh 513 | git stash push --all 514 | ``` 515 | 516 | ## Show list of all saved stashes 517 | ```sh 518 | git stash list 519 | ``` 520 | 521 | ## Show the contents of any stash in patch form 522 | ```sh 523 | git stash show -p 524 | ``` 525 | 526 | ## Apply any stash without deleting from the stashed list 527 | ```sh 528 | git stash apply 529 | ``` 530 | 531 | ## Apply last stashed state and delete it from stashed list 532 | ```sh 533 | git stash pop 534 | ``` 535 | 536 | 537 | __Alternatives:__ 538 | ```sh 539 | git stash apply stash@{0} && git stash drop stash@{0} 540 | ``` 541 | 542 | ## Delete all stored stashes 543 | ```sh 544 | git stash clear 545 | ``` 546 | 547 | 548 | __Alternatives:__ 549 | ```sh 550 | git stash drop 551 | ``` 552 | 553 | ## Grab a single file from a stash 554 | ```sh 555 | git checkout -- 556 | ``` 557 | 558 | 559 | __Alternatives:__ 560 | ```sh 561 | git checkout stash@{0} -- 562 | ``` 563 | 564 | ## Show all tracked files 565 | ```sh 566 | git ls-files -t 567 | ``` 568 | 569 | ## Show all untracked files 570 | ```sh 571 | git ls-files --others 572 | ``` 573 | 574 | ## Show all ignored files 575 | ```sh 576 | git ls-files --others -i --exclude-standard 577 | ``` 578 | 579 | ## Create new working tree from a repository (git 2.5) 580 | ```sh 581 | git worktree add -b 582 | ``` 583 | 584 | ## Create new working tree from HEAD state 585 | ```sh 586 | git worktree add --detach HEAD 587 | ``` 588 | 589 | ## Untrack files without deleting 590 | ```sh 591 | git rm --cached 592 | ``` 593 | 594 | 595 | __Alternatives:__ 596 | ```sh 597 | git rm --cached -r 598 | ``` 599 | 600 | ## Before deleting untracked files/directory, do a dry run to get the list of these files/directories 601 | ```sh 602 | git clean -n 603 | ``` 604 | 605 | ## Forcefully remove untracked files 606 | ```sh 607 | git clean -f 608 | ``` 609 | 610 | ## Forcefully remove untracked directory 611 | ```sh 612 | git clean -f -d 613 | ``` 614 | 615 | ## Update all the submodules 616 | ```sh 617 | git submodule foreach git pull 618 | ``` 619 | 620 | 621 | __Alternatives:__ 622 | ```sh 623 | git submodule update --init --recursive 624 | ``` 625 | 626 | 627 | ```sh 628 | git submodule update --remote 629 | ``` 630 | 631 | ## Show all commits in the current branch yet to be merged to master 632 | ```sh 633 | git cherry -v master 634 | ``` 635 | 636 | 637 | __Alternatives:__ 638 | ```sh 639 | git cherry -v master 640 | ``` 641 | 642 | ## Rename a branch 643 | ```sh 644 | git branch -m 645 | ``` 646 | 647 | 648 | __Alternatives:__ 649 | ```sh 650 | git branch -m [] 651 | ``` 652 | 653 | ## Rebases 'feature' to 'master' and merges it in to master 654 | ```sh 655 | git rebase master feature && git checkout master && git merge - 656 | ``` 657 | 658 | ## Archive the `master` branch 659 | ```sh 660 | git archive master --format=zip --output=master.zip 661 | ``` 662 | 663 | ## Modify previous commit without modifying the commit message 664 | ```sh 665 | git add --all && git commit --amend --no-edit 666 | ``` 667 | 668 | ## Prunes references to remove branches that have been deleted in the remote. 669 | ```sh 670 | git fetch -p 671 | ``` 672 | 673 | 674 | __Alternatives:__ 675 | ```sh 676 | git remote prune origin 677 | ``` 678 | 679 | ## Delete local branches that has been squash and merged in the remote. 680 | ```sh 681 | git branch -vv | grep ': gone]' | awk '{print }' | xargs git branch -D 682 | ``` 683 | 684 | ## Retrieve the commit hash of the initial revision. 685 | ```sh 686 | git rev-list --reverse HEAD | head -1 687 | ``` 688 | 689 | 690 | __Alternatives:__ 691 | ```sh 692 | git rev-list --max-parents=0 HEAD 693 | ``` 694 | 695 | 696 | ```sh 697 | git log --pretty=oneline | tail -1 | cut -c 1-40 698 | ``` 699 | 700 | 701 | ```sh 702 | git log --pretty=oneline --reverse | head -1 | cut -c 1-40 703 | ``` 704 | 705 | ## Visualize the version tree. 706 | ```sh 707 | git log --pretty=oneline --graph --decorate --all 708 | ``` 709 | 710 | 711 | __Alternatives:__ 712 | ```sh 713 | gitk --all 714 | ``` 715 | 716 | 717 | ```sh 718 | git log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d' 719 | ``` 720 | 721 | ## Visualize the tree including commits that are only referenced from reflogs 722 | ```sh 723 | git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all) 724 | ``` 725 | 726 | ## Deploying git tracked subfolder to gh-pages 727 | ```sh 728 | git subtree push --prefix subfolder_name origin gh-pages 729 | ``` 730 | 731 | ## Adding a project to repo using subtree 732 | ```sh 733 | git subtree add --prefix=/ --squash git@github.com:/.git master 734 | ``` 735 | 736 | ## Get latest changes in your repo for a linked project using subtree 737 | ```sh 738 | git subtree pull --prefix=/ --squash git@github.com:/.git master 739 | ``` 740 | 741 | ## Export a branch with history to a file. 742 | ```sh 743 | git bundle create 744 | ``` 745 | 746 | ## Import from a bundle 747 | ```sh 748 | git clone repo.bundle -b 749 | ``` 750 | 751 | ## Get the name of current branch. 752 | ```sh 753 | git rev-parse --abbrev-ref HEAD 754 | ``` 755 | 756 | ## Ignore one file on commit (e.g. Changelog). 757 | ```sh 758 | git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog 759 | ``` 760 | 761 | ## Stash changes before rebasing 762 | ```sh 763 | git rebase --autostash 764 | ``` 765 | 766 | ## Fetch pull request by ID to a local branch 767 | ```sh 768 | git fetch origin pull//head: 769 | ``` 770 | 771 | 772 | __Alternatives:__ 773 | ```sh 774 | git pull origin pull//head: 775 | ``` 776 | 777 | ## Show the most recent tag on the current branch. 778 | ```sh 779 | git describe --tags --abbrev=0 780 | ``` 781 | 782 | ## Show inline word diff. 783 | ```sh 784 | git diff --word-diff 785 | ``` 786 | 787 | ## Show changes using common diff tools. 788 | ```sh 789 | git difftool [-t ] 790 | ``` 791 | 792 | ## Don’t consider changes for tracked file. 793 | ```sh 794 | git update-index --assume-unchanged 795 | ``` 796 | 797 | ## Undo assume-unchanged. 798 | ```sh 799 | git update-index --no-assume-unchanged 800 | ``` 801 | 802 | ## Clean the files from `.gitignore`. 803 | ```sh 804 | git clean -X -f 805 | ``` 806 | 807 | ## Restore deleted file. 808 | ```sh 809 | git checkout -- 810 | ``` 811 | 812 | ## Restore file to a specific commit-hash 813 | ```sh 814 | git checkout -- 815 | ``` 816 | 817 | ## Always rebase instead of merge on pull. 818 | ```sh 819 | git config --global pull.rebase true 820 | ``` 821 | 822 | 823 | __Alternatives:__ 824 | ```sh 825 | #git < 1.7.9 826 | git config --global branch.autosetuprebase always 827 | ``` 828 | 829 | ## List all the alias and configs. 830 | ```sh 831 | git config --list 832 | ``` 833 | 834 | ## Make git case sensitive. 835 | ```sh 836 | git config --global core.ignorecase false 837 | ``` 838 | 839 | ## Add custom editors. 840 | ```sh 841 | git config --global core.editor '$EDITOR' 842 | ``` 843 | 844 | ## Auto correct typos. 845 | ```sh 846 | git config --global help.autocorrect 1 847 | ``` 848 | 849 | ## Check if the change was a part of a release. 850 | ```sh 851 | git name-rev --name-only 852 | ``` 853 | 854 | ## Dry run. (any command that supports dry-run flag should do.) 855 | ```sh 856 | git clean -fd --dry-run 857 | ``` 858 | 859 | ## Marks your commit as a fix of a previous commit. 860 | ```sh 861 | git commit --fixup 862 | ``` 863 | 864 | ## Squash fixup commits normal commits. 865 | ```sh 866 | git rebase -i --autosquash 867 | ``` 868 | 869 | ## Skip staging area during commit. 870 | ```sh 871 | git commit --only 872 | ``` 873 | 874 | ## Interactive staging. 875 | ```sh 876 | git add -i 877 | ``` 878 | 879 | ## List ignored files. 880 | ```sh 881 | git check-ignore * 882 | ``` 883 | 884 | ## Status of ignored files. 885 | ```sh 886 | git status --ignored 887 | ``` 888 | 889 | ## Commits in Branch1 that are not in Branch2 890 | ```sh 891 | git log Branch1 ^Branch2 892 | ``` 893 | 894 | ## List n last commits 895 | ```sh 896 | git log - 897 | ``` 898 | 899 | 900 | __Alternatives:__ 901 | ```sh 902 | git log -n 903 | ``` 904 | 905 | ## Reuse recorded resolution, record and reuse previous conflicts resolutions. 906 | ```sh 907 | git config --global rerere.enabled 1 908 | ``` 909 | 910 | ## Open all conflicted files in an editor. 911 | ```sh 912 | git diff --name-only | uniq | xargs $EDITOR 913 | ``` 914 | 915 | ## Count unpacked number of objects and their disk consumption. 916 | ```sh 917 | git count-objects --human-readable 918 | ``` 919 | 920 | ## Prune all unreachable objects from the object database. 921 | ```sh 922 | git gc --prune=now --aggressive 923 | ``` 924 | 925 | ## Instantly browse your working repository in gitweb. 926 | ```sh 927 | git instaweb [--local] [--httpd=] [--port=] [--browser=] 928 | ``` 929 | 930 | ## View the GPG signatures in the commit log 931 | ```sh 932 | git log --show-signature 933 | ``` 934 | 935 | ## Remove entry in the global config. 936 | ```sh 937 | git config --global --unset 938 | ``` 939 | 940 | ## Checkout a new branch without any history 941 | ```sh 942 | git checkout --orphan 943 | ``` 944 | 945 | ## Extract file from another branch. 946 | ```sh 947 | git show : 948 | ``` 949 | 950 | ## List only the root and merge commits. 951 | ```sh 952 | git log --first-parent 953 | ``` 954 | 955 | ## Change previous two commits with an interactive rebase. 956 | ```sh 957 | git rebase --interactive HEAD~2 958 | ``` 959 | 960 | ## List all branch is WIP 961 | ```sh 962 | git checkout master && git branch --no-merged 963 | ``` 964 | 965 | ## Find guilty with binary search 966 | ```sh 967 | git bisect start # Search start 968 | git bisect bad # Set point to bad commit 969 | git bisect good v2.6.13-rc2 # Set point to good commit|tag 970 | git bisect bad # Say current state is bad 971 | git bisect good # Say current state is good 972 | git bisect reset # Finish search 973 | 974 | ``` 975 | 976 | ## Bypass pre-commit and commit-msg githooks 977 | ```sh 978 | git commit --no-verify 979 | ``` 980 | 981 | ## List commits and changes to a specific file (even through renaming) 982 | ```sh 983 | git log --follow -p -- 984 | ``` 985 | 986 | ## Clone a single branch 987 | ```sh 988 | git clone -b --single-branch https://github.com/user/repo.git 989 | ``` 990 | 991 | ## Create and switch new branch 992 | ```sh 993 | git checkout -b 994 | ``` 995 | 996 | 997 | __Alternatives:__ 998 | ```sh 999 | git branch && git checkout 1000 | ``` 1001 | 1002 | ```sh 1003 | git switch -c 1004 | ``` 1005 | 1006 | ## Ignore file mode changes on commits 1007 | ```sh 1008 | git config core.fileMode false 1009 | ``` 1010 | 1011 | ## Turn off git colored terminal output 1012 | ```sh 1013 | git config --global color.ui false 1014 | ``` 1015 | 1016 | ## Specific color settings 1017 | ```sh 1018 | git config --global 1019 | ``` 1020 | 1021 | ## Show all local branches ordered by recent commits 1022 | ```sh 1023 | git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ 1024 | ``` 1025 | 1026 | ## Find lines matching the pattern (regex or string) in tracked files 1027 | ```sh 1028 | git grep --heading --line-number 'foo bar' 1029 | ``` 1030 | 1031 | ## Clone a shallow copy of a repository 1032 | ```sh 1033 | git clone https://github.com/user/repo.git --depth 1 1034 | ``` 1035 | 1036 | ## Search Commit log across all branches for given text 1037 | ```sh 1038 | git log --all --grep='' 1039 | ``` 1040 | 1041 | ## Get first commit in a branch (from master) 1042 | ```sh 1043 | git log --oneline master.. | tail -1 1044 | ``` 1045 | 1046 | 1047 | __Alternatives:__ 1048 | ```sh 1049 | git log --reverse master.. | head -6 1050 | ``` 1051 | 1052 | ## Unstaging Staged file 1053 | ```sh 1054 | git reset HEAD 1055 | ``` 1056 | 1057 | ## Force push to Remote Repository 1058 | ```sh 1059 | git push -f 1060 | ``` 1061 | 1062 | ## Adding Remote name 1063 | ```sh 1064 | git remote add 1065 | ``` 1066 | 1067 | ## List all currently configured remotes 1068 | ```sh 1069 | git remote -v 1070 | ``` 1071 | 1072 | ## Show the author, time and last revision made to each line of a given file 1073 | ```sh 1074 | git blame 1075 | ``` 1076 | 1077 | ## Group commits by authors and title 1078 | ```sh 1079 | git shortlog 1080 | ``` 1081 | 1082 | ## Forced push but still ensure you don't overwrite other's work 1083 | ```sh 1084 | git push --force-with-lease 1085 | ``` 1086 | 1087 | ## Show how many lines does an author contribute 1088 | ```sh 1089 | git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | gawk '{ add += ; subs += ; loc += - } END { printf "added lines: %s removed lines: %s total lines: %s 1090 | ", add, subs, loc }' - 1091 | ``` 1092 | 1093 | 1094 | __Alternatives:__ 1095 | ```sh 1096 | git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | awk '{ add += ; subs += ; loc += - } END { printf "added lines: %s, removed lines: %s, total lines: %s 1097 | ", add, subs, loc }' - # on Mac OSX 1098 | ``` 1099 | 1100 | ## Revert: Reverting an entire merge 1101 | ```sh 1102 | git revert -m 1 1103 | ``` 1104 | 1105 | ## Number of commits in a branch 1106 | ```sh 1107 | git rev-list --count 1108 | ``` 1109 | 1110 | ## Alias: git undo 1111 | ```sh 1112 | git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f' 1113 | ``` 1114 | 1115 | ## Add object notes 1116 | ```sh 1117 | git notes add -m 'Note on the previous commit....' 1118 | ``` 1119 | 1120 | ## Show all the git-notes 1121 | ```sh 1122 | git log --show-notes='*' 1123 | ``` 1124 | 1125 | ## Apply commit from another repository 1126 | ```sh 1127 | git --git-dir=/.git format-patch -k -1 --stdout | git am -3 -k 1128 | ``` 1129 | 1130 | ## Specific fetch reference 1131 | ```sh 1132 | git fetch origin master:refs/remotes/origin/mymaster 1133 | ``` 1134 | 1135 | ## Find common ancestor of two branches 1136 | ```sh 1137 | git merge-base 1138 | ``` 1139 | 1140 | ## List unpushed git commits 1141 | ```sh 1142 | git log --branches --not --remotes 1143 | ``` 1144 | 1145 | 1146 | __Alternatives:__ 1147 | ```sh 1148 | git log @{u}.. 1149 | ``` 1150 | 1151 | 1152 | ```sh 1153 | git cherry -v 1154 | ``` 1155 | 1156 | ## Add everything, but whitespace changes 1157 | ```sh 1158 | git diff --ignore-all-space | git apply --cached 1159 | ``` 1160 | 1161 | ## Edit [local/global] git config 1162 | ```sh 1163 | git config [--global] --edit 1164 | ``` 1165 | 1166 | ## blame on certain range 1167 | ```sh 1168 | git blame -L , 1169 | ``` 1170 | 1171 | ## Show a Git logical variable. 1172 | ```sh 1173 | git var -l | 1174 | ``` 1175 | 1176 | ## Preformatted patch file. 1177 | ```sh 1178 | git format-patch -M upstream..topic 1179 | ``` 1180 | 1181 | ## Get the repo name. 1182 | ```sh 1183 | git rev-parse --show-toplevel 1184 | ``` 1185 | 1186 | ## logs between date range 1187 | ```sh 1188 | git log --since='FEB 1 2017' --until='FEB 14 2017' 1189 | ``` 1190 | 1191 | ## Exclude author from logs 1192 | ```sh 1193 | git log --perl-regexp --author='^((?!excluded-author-regex).*) 1194 | 1195 | ``` 1196 | 1197 | ## Generates a summary of pending changes 1198 | ```sh 1199 | git request-pull v1.0 https://git.ko.xz/project master:for-linus 1200 | ``` 1201 | 1202 | ## List references in a remote repository 1203 | ```sh 1204 | git ls-remote git://git.kernel.org/pub/scm/git/git.git 1205 | ``` 1206 | 1207 | ## Backup untracked files. 1208 | ```sh 1209 | git ls-files --others -i --exclude-standard | xargs zip untracked.zip 1210 | ``` 1211 | 1212 | ## List all git aliases 1213 | ```sh 1214 | git config -l | grep alias | sed 's/^alias\.//g' 1215 | ``` 1216 | 1217 | 1218 | __Alternatives:__ 1219 | ```sh 1220 | git config -l | grep alias | cut -d '.' -f 2 1221 | ``` 1222 | 1223 | ## Show git status short 1224 | ```sh 1225 | git status --short --branch 1226 | ``` 1227 | 1228 | ## Checkout a commit prior to a day ago 1229 | ```sh 1230 | git checkout master@{yesterday} 1231 | ``` 1232 | 1233 | ## Push the current branch to the same name on the remote repository 1234 | ```sh 1235 | git push origin HEAD 1236 | ``` 1237 | 1238 | ## Push a new local branch to remote repository and track 1239 | ```sh 1240 | git push -u origin 1241 | ``` 1242 | 1243 | ## Change a branch base 1244 | ```sh 1245 | git rebase --onto 1246 | ``` 1247 | 1248 | ## Use SSH instead of HTTPs for remotes 1249 | ```sh 1250 | git config --global url.'git@github.com:'.insteadOf 'https://github.com/' 1251 | ``` 1252 | 1253 | ## Update a submodule to the latest commit 1254 | ```sh 1255 | cd 1256 | git pull origin 1257 | cd 1258 | git add 1259 | git commit -m "submodule updated" 1260 | ``` 1261 | 1262 | ## Prevent auto replacing LF with CRLF 1263 | ```sh 1264 | git config --global core.autocrlf false 1265 | ``` 1266 | 1267 | 1268 | 1269 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | ## Easy steps: 2 | 3 | * [Fork](https://github.com/git-tips/tips/network) the repo. 4 | 5 | * Install the deps: 6 | ```sh 7 | $ cd tips && npm install 8 | ``` 9 | 10 | :warning: don't fail to think that this is optional, because if you don't install the dependencies you won't get the benefit of auto-updating README and TOC and your PR will likely to not get merged because of that. 11 | 12 | * Edit [tips.json](./tips.json) to add your tip in the below format: 13 | 14 | ```js 15 | { 16 | "title": , 17 | "tip": , 18 | "alternatives": [Optional list of alternatives] 19 | } 20 | ``` 21 | 22 | * Commit, push and send a PR! 23 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tips", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "101": { 8 | "version": "1.6.3", 9 | "resolved": "https://registry.npmjs.org/101/-/101-1.6.3.tgz", 10 | "integrity": "sha512-4dmQ45yY0Dx24Qxp+zAsNLlMF6tteCyfVzgbulvSyC7tCyd3V8sW76sS0tHq8NpcbXfWTKasfyfzU1Kd86oKzw==", 11 | "dev": true, 12 | "requires": { 13 | "clone": "^1.0.2", 14 | "deep-eql": "^0.1.3", 15 | "keypather": "^1.10.2" 16 | } 17 | }, 18 | "1-liners": { 19 | "version": "0.3.6", 20 | "resolved": "https://registry.npmjs.org/1-liners/-/1-liners-0.3.6.tgz", 21 | "integrity": "sha1-SDD+eLdTejaZ+IpdQqjtwa9mB/8=", 22 | "dev": true 23 | }, 24 | "ansi-regex": { 25 | "version": "2.1.1", 26 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", 27 | "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", 28 | "dev": true 29 | }, 30 | "ansi-styles": { 31 | "version": "2.2.1", 32 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", 33 | "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", 34 | "dev": true 35 | }, 36 | "array-find": { 37 | "version": "1.0.0", 38 | "resolved": "https://registry.npmjs.org/array-find/-/array-find-1.0.0.tgz", 39 | "integrity": "sha1-bI4obRHtdoMn+OYuzuhzU8o+eLg=", 40 | "dev": true 41 | }, 42 | "base64-js": { 43 | "version": "0.0.2", 44 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-0.0.2.tgz", 45 | "integrity": "sha1-Ak8Pcq+iW3X5wO5zzU9V7Bvtl4Q=", 46 | "dev": true 47 | }, 48 | "bops": { 49 | "version": "0.0.6", 50 | "resolved": "https://registry.npmjs.org/bops/-/bops-0.0.6.tgz", 51 | "integrity": "sha1-CC0dVfoB5g29wuvC26N/ZZVUzzo=", 52 | "dev": true, 53 | "requires": { 54 | "base64-js": "0.0.2", 55 | "to-utf8": "0.0.1" 56 | } 57 | }, 58 | "chalk": { 59 | "version": "1.1.3", 60 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", 61 | "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", 62 | "dev": true, 63 | "requires": { 64 | "ansi-styles": "^2.2.1", 65 | "escape-string-regexp": "^1.0.2", 66 | "has-ansi": "^2.0.0", 67 | "strip-ansi": "^3.0.0", 68 | "supports-color": "^2.0.0" 69 | } 70 | }, 71 | "clone": { 72 | "version": "1.0.4", 73 | "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", 74 | "integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=", 75 | "dev": true 76 | }, 77 | "concat-stream": { 78 | "version": "1.2.1", 79 | "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.2.1.tgz", 80 | "integrity": "sha1-81EAtsRjeL+6i2uA+fDQzN8T3GA=", 81 | "dev": true, 82 | "requires": { 83 | "bops": "0.0.6" 84 | } 85 | }, 86 | "deep-eql": { 87 | "version": "0.1.3", 88 | "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", 89 | "integrity": "sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=", 90 | "dev": true, 91 | "requires": { 92 | "type-detect": "0.1.1" 93 | } 94 | }, 95 | "defined": { 96 | "version": "1.0.0", 97 | "resolved": "https://registry.npmjs.org/defined/-/defined-1.0.0.tgz", 98 | "integrity": "sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=", 99 | "dev": true 100 | }, 101 | "doxie": { 102 | "version": "0.2.4", 103 | "resolved": "https://registry.npmjs.org/doxie/-/doxie-0.2.4.tgz", 104 | "integrity": "sha1-KZltv1dg/OdNvLTXnGAjHYoXu4U=", 105 | "dev": true, 106 | "requires": { 107 | "1-liners": "^0.3.2", 108 | "chalk": "^1.0.0", 109 | "doxie-core": "^0.3.1", 110 | "stream-to-json": "^0.0.1", 111 | "tiny-error": "^0.2.1" 112 | } 113 | }, 114 | "doxie-core": { 115 | "version": "0.3.1", 116 | "resolved": "https://registry.npmjs.org/doxie-core/-/doxie-core-0.3.1.tgz", 117 | "integrity": "sha1-PS+RQ+WF45Cpgwjcnk7zjxPPQss=", 118 | "dev": true, 119 | "requires": { 120 | "1-liners": "^0.3.0", 121 | "chalk": "^1.0.0", 122 | "tiny-error": "^0.2.1" 123 | } 124 | }, 125 | "doxie.append": { 126 | "version": "0.1.0", 127 | "resolved": "https://registry.npmjs.org/doxie.append/-/doxie.append-0.1.0.tgz", 128 | "integrity": "sha1-yHRoUEL18wlKTQwzNsPklMNpdOE=", 129 | "dev": true, 130 | "requires": { 131 | "object-assign": "^3.0.0" 132 | }, 133 | "dependencies": { 134 | "object-assign": { 135 | "version": "3.0.0", 136 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", 137 | "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", 138 | "dev": true 139 | } 140 | } 141 | }, 142 | "doxie.inject": { 143 | "version": "0.1.1", 144 | "resolved": "https://registry.npmjs.org/doxie.inject/-/doxie.inject-0.1.1.tgz", 145 | "integrity": "sha1-/QNYT4segOZEtcuUdpr+RH94oEc=", 146 | "dev": true, 147 | "requires": { 148 | "1-liners": "^0.3.2", 149 | "array-find": "^1.0.0", 150 | "chalk": "^1.0.0", 151 | "defined": "^1.0.0", 152 | "object-assign": "^3.0.0", 153 | "tiny-error": "^0.2.1" 154 | }, 155 | "dependencies": { 156 | "object-assign": { 157 | "version": "3.0.0", 158 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", 159 | "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", 160 | "dev": true 161 | } 162 | } 163 | }, 164 | "doxie.output": { 165 | "version": "0.3.0", 166 | "resolved": "https://registry.npmjs.org/doxie.output/-/doxie.output-0.3.0.tgz", 167 | "integrity": "sha1-4H4Stn2qX8KLPsZn0HAv1ziZitE=", 168 | "dev": true, 169 | "requires": { 170 | "1-liners": "^0.3.0", 171 | "object-assign": "^3.0.0" 172 | }, 173 | "dependencies": { 174 | "object-assign": { 175 | "version": "3.0.0", 176 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", 177 | "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", 178 | "dev": true 179 | } 180 | } 181 | }, 182 | "doxie.render": { 183 | "version": "0.3.2", 184 | "resolved": "https://registry.npmjs.org/doxie.render/-/doxie.render-0.3.2.tgz", 185 | "integrity": "sha1-Mva37g88NSSokT08grn6uqoKGPA=", 186 | "dev": true, 187 | "requires": { 188 | "1-liners": "^0.3.1", 189 | "chalk": "^1.0.0", 190 | "object-assign": "^3.0.0", 191 | "tiny-error": "^0.2.1" 192 | }, 193 | "dependencies": { 194 | "object-assign": { 195 | "version": "3.0.0", 196 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", 197 | "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", 198 | "dev": true 199 | } 200 | } 201 | }, 202 | "escape-string-regexp": { 203 | "version": "1.0.5", 204 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", 205 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", 206 | "dev": true 207 | }, 208 | "has-ansi": { 209 | "version": "2.0.0", 210 | "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", 211 | "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", 212 | "dev": true, 213 | "requires": { 214 | "ansi-regex": "^2.0.0" 215 | } 216 | }, 217 | "husky": { 218 | "version": "5.2.0", 219 | "resolved": "https://registry.npmjs.org/husky/-/husky-5.2.0.tgz", 220 | "integrity": "sha512-AM8T/auHXRBxlrfPVLKP6jt49GCM2Zz47m8G3FOMsLmTv8Dj/fKVWE0Rh2d4Qrvmy131xEsdQnb3OXRib67PGg==", 221 | "dev": true 222 | }, 223 | "keypather": { 224 | "version": "1.10.2", 225 | "resolved": "https://registry.npmjs.org/keypather/-/keypather-1.10.2.tgz", 226 | "integrity": "sha1-4ESWMtSz5RbyHMAUznxWRP3c5hQ=", 227 | "dev": true, 228 | "requires": { 229 | "101": "^1.0.0" 230 | } 231 | }, 232 | "object-assign": { 233 | "version": "4.1.1", 234 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", 235 | "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", 236 | "dev": true 237 | }, 238 | "once": { 239 | "version": "1.3.3", 240 | "resolved": "https://registry.npmjs.org/once/-/once-1.3.3.tgz", 241 | "integrity": "sha1-suJhVXzkwxTsgwTz+oJmPkKXyiA=", 242 | "dev": true, 243 | "requires": { 244 | "wrappy": "1" 245 | } 246 | }, 247 | "stream-to-json": { 248 | "version": "0.0.1", 249 | "resolved": "https://registry.npmjs.org/stream-to-json/-/stream-to-json-0.0.1.tgz", 250 | "integrity": "sha1-8DDyt47TjkkpPbiFZTarzCZ3FHM=", 251 | "dev": true, 252 | "requires": { 253 | "concat-stream": "~1.2.0", 254 | "once": "~1.3.0" 255 | } 256 | }, 257 | "strip-ansi": { 258 | "version": "3.0.1", 259 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", 260 | "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", 261 | "dev": true, 262 | "requires": { 263 | "ansi-regex": "^2.0.0" 264 | } 265 | }, 266 | "supports-color": { 267 | "version": "2.0.0", 268 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", 269 | "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", 270 | "dev": true 271 | }, 272 | "tiny-error": { 273 | "version": "0.2.3", 274 | "resolved": "https://registry.npmjs.org/tiny-error/-/tiny-error-0.2.3.tgz", 275 | "integrity": "sha1-KHas/leFGwcUMTwVNd/HBgp8Cbs=", 276 | "dev": true, 277 | "requires": { 278 | "101": "^1.0.0", 279 | "object-assign": "^4.0.1" 280 | } 281 | }, 282 | "to-utf8": { 283 | "version": "0.0.1", 284 | "resolved": "https://registry.npmjs.org/to-utf8/-/to-utf8-0.0.1.tgz", 285 | "integrity": "sha1-0Xrqcv8vujm55DYBvns/9y4ImFI=", 286 | "dev": true 287 | }, 288 | "type-detect": { 289 | "version": "0.1.1", 290 | "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-0.1.1.tgz", 291 | "integrity": "sha1-C6XsKohWQORw6k6FBZcZANrFiCI=", 292 | "dev": true 293 | }, 294 | "wrappy": { 295 | "version": "1.0.2", 296 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 297 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", 298 | "dev": true 299 | } 300 | } 301 | } 302 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tips", 3 | "version": "1.0.0", 4 | "description": "collection of git tips", 5 | "main": "index.js", 6 | "private": "true", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1", 9 | "precommit": "npm run generate && git add README.md", 10 | "update-readme": "echo 'Updating the readme…'; doxie --render < ./tips.json --inject into README.md && echo '…done!'", 11 | "update-toc": "echo 'Updating the table of contents…'; doxie --render .doxie.render.toc.js < ./tips.json --append '\n' --inject into README.md as toc && echo '…done!'", 12 | "generate": "npm run update-readme; npm run update-toc" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/npm-tips/tips.git" 17 | }, 18 | "keywords": [ 19 | "npm", 20 | "tips" 21 | ], 22 | "contributors": [ 23 | "hemanth" 24 | ], 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/git-tips/tips/issues" 28 | }, 29 | "homepage": "https://github.com/git-tips/tips#readme", 30 | "devDependencies": { 31 | "doxie": "^0.2.2", 32 | "doxie.append": "^0.1.0", 33 | "doxie.inject": "^0.1.1", 34 | "doxie.output": "^0.3.0", 35 | "doxie.render": "^0.3.0", 36 | "husky": "^5.0.9" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tips.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "title": "Everyday Git in twenty commands or so", 3 | "tip": "git help everyday" 4 | }, { 5 | "title": "Show helpful guides that come with Git", 6 | "tip": "git help -g" 7 | }, { 8 | "title": "Search change by content", 9 | "tip": "git log -S''" 10 | }, { 11 | "title": "Show changes over time for specific file", 12 | "tip": "git log -p " 13 | }, { 14 | "title": "Remove sensitive data from history, after a push", 15 | "tip": "git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all" 16 | }, { 17 | "title": "Sync with remote, overwrite local changes", 18 | "tip": "git fetch origin && git reset --hard origin/master && git clean -f -d" 19 | }, { 20 | "title": "List of all files till a commit", 21 | "tip": "git ls-tree --name-only -r " 22 | }, { 23 | "title": "Git reset first commit", 24 | "tip": "git update-ref -d HEAD" 25 | }, { 26 | "title": "Reset: preserve uncommitted local changes", 27 | "tip": "git reset --keep " 28 | }, { 29 | "title": "List all the conflicted files", 30 | "tip": "git diff --name-only --diff-filter=U" 31 | }, { 32 | "title": "List of all files changed in a commit", 33 | "tip": "git diff-tree --no-commit-id --name-only -r " 34 | }, { 35 | "title": "Unstaged changes since last commit", 36 | "tip": "git diff" 37 | }, { 38 | "title": "Changes staged for commit", 39 | "tip": "git diff --cached", 40 | "alternatives": ["git diff --staged"] 41 | }, { 42 | "title": "Show both staged and unstaged changes", 43 | "tip": "git diff HEAD" 44 | }, { 45 | "title": "List all branches that are already merged into master", 46 | "tip": "git branch --merged master" 47 | }, { 48 | "title": "Quickly switch to the previous branch", 49 | "tip": "git checkout -", 50 | "alternatives": ["git checkout @{-1}"] 51 | }, { 52 | "title": "Remove branches that have already been merged with master", 53 | "tip": "git branch --merged master | grep -v '^\\*' | xargs -n 1 git branch -d", 54 | "alternatives": ["git branch --merged master | grep -v '^\\*\\| master' | xargs -n 1 git branch -d # will not delete master if master is not checked out"] 55 | }, { 56 | "title": "List all branches and their upstreams, as well as last commit on branch", 57 | "tip": "git branch -vv" 58 | }, { 59 | "title": "Track upstream branch", 60 | "tip": "git branch -u origin/mybranch" 61 | }, { 62 | "title": "Delete local branch", 63 | "tip": "git branch -d " 64 | }, { 65 | "title": "Delete remote branch", 66 | "tip": "git push origin --delete ", 67 | "alternatives": ["git push origin :", "git branch -dr "] 68 | }, { 69 | "title": "Create local tag", 70 | "tip": "git tag " 71 | }, { 72 | "title": "Delete local tag", 73 | "tip": "git tag -d " 74 | }, { 75 | "title": "Delete remote tag", 76 | "tip": "git push origin :refs/tags/" 77 | }, { 78 | "title": "Undo local changes with the content in index(staging)", 79 | "tip": "git checkout -- " 80 | }, { 81 | "title": "Revert: Undo a commit by creating a new commit", 82 | "tip": "git revert " 83 | }, { 84 | "title": "Reset: Discard commits, advised for private branch", 85 | "tip": "git reset " 86 | }, { 87 | "title": "Reword the previous commit message", 88 | "tip": "git commit -v --amend" 89 | }, { 90 | "title": "See commit history for just the current branch", 91 | "tip": "git cherry -v master" 92 | }, { 93 | "title": "Amend author.", 94 | "tip": "git commit --amend --author='Author Name '" 95 | }, { 96 | "title": "Reset author, after author has been changed in the global config.", 97 | "tip": "git commit --amend --reset-author --no-edit" 98 | }, { 99 | "title": "Changing a remote's URL", 100 | "tip": "git remote set-url origin " 101 | }, { 102 | "title": "Get list of all remote references", 103 | "tip": "git remote", 104 | "alternatives": ["git remote show"] 105 | }, { 106 | "title": "Get list of all local and remote branches", 107 | "tip": "git branch -a" 108 | }, { 109 | "title": "Get only remote branches", 110 | "tip": "git branch -r" 111 | }, { 112 | "title": "Stage parts of a changed file, instead of the entire file", 113 | "tip": "git add -p" 114 | }, { 115 | "title": "Get git bash completion", 116 | "tip": "curl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc" 117 | }, { 118 | "title": "What changed since two weeks?", 119 | "tip": "git log --no-merges --raw --since='2 weeks ago'", 120 | "alternatives": ["git whatchanged --since='2 weeks ago'"] 121 | }, { 122 | "title": "See all commits made since forking from master", 123 | "tip": "git log --no-merges --stat --reverse master.." 124 | }, { 125 | "title": "Pick commits across branches using cherry-pick", 126 | "tip": "git checkout && git cherry-pick " 127 | }, { 128 | "title": "Find out branches containing commit-hash", 129 | "tip": "git branch -a --contains ", 130 | "alternatives": ["git branch --contains "] 131 | }, { 132 | "title": "Git Aliases", 133 | "tip": "git config --global alias. \ngit config --global alias.st status" 134 | }, { 135 | "title": "Saving current state of tracked files without committing", 136 | "tip": "git stash", 137 | "alternatives": ["git stash push"] 138 | }, { 139 | "title": "Saving current state of unstaged changes to tracked files", 140 | "tip": "git stash -k", 141 | "alternatives": ["git stash --keep-index", "git stash push --keep-index"] 142 | }, { 143 | "title": "Saving current state including untracked files", 144 | "tip": "git stash -u", 145 | "alternatives": ["git stash push -u", "git stash push --include-untracked"] 146 | }, { 147 | "title": "Saving current state with message", 148 | "tip": "git stash push -m ", 149 | "alternatives": ["git stash push --message "] 150 | }, { 151 | "title": "Saving current state of all files (ignored, untracked, and tracked)", 152 | "tip": "git stash -a", 153 | "alternatives": ["git stash --all", "git stash push --all"] 154 | }, { 155 | "title": "Show list of all saved stashes", 156 | "tip": "git stash list" 157 | }, { 158 | "title": "Show the contents of any stash in patch form", 159 | "tip": "git stash show -p " 160 | }, { 161 | "title": "Apply any stash without deleting from the stashed list", 162 | "tip": "git stash apply " 163 | }, { 164 | "title": "Apply last stashed state and delete it from stashed list", 165 | "tip": "git stash pop", 166 | "alternatives": ["git stash apply stash@{0} && git stash drop stash@{0}"] 167 | }, { 168 | "title": "Delete all stored stashes", 169 | "tip": "git stash clear", 170 | "alternatives": ["git stash drop "] 171 | }, { 172 | "title": "Grab a single file from a stash", 173 | "tip": "git checkout -- ", 174 | "alternatives": ["git checkout stash@{0} -- "] 175 | }, { 176 | "title": "Show all tracked files", 177 | "tip": "git ls-files -t" 178 | }, { 179 | "title": "Show all untracked files", 180 | "tip": "git ls-files --others" 181 | }, { 182 | "title": "Show all ignored files", 183 | "tip": "git ls-files --others -i --exclude-standard" 184 | }, { 185 | "title": "Create new working tree from a repository (git 2.5)", 186 | "tip": "git worktree add -b " 187 | }, { 188 | "title": "Create new working tree from HEAD state", 189 | "tip": "git worktree add --detach HEAD" 190 | }, { 191 | "title": "Untrack files without deleting", 192 | "tip": "git rm --cached ", 193 | "alternatives": ["git rm --cached -r "] 194 | }, { 195 | "title": "Before deleting untracked files/directory, do a dry run to get the list of these files/directories", 196 | "tip": "git clean -n" 197 | }, { 198 | "title": "Forcefully remove untracked files", 199 | "tip": "git clean -f" 200 | }, { 201 | "title": "Forcefully remove untracked directory", 202 | "tip": "git clean -f -d" 203 | }, { 204 | "title": "Update all the submodules", 205 | "tip": "git submodule foreach git pull", 206 | "alternatives": ["git submodule update --init --recursive", "git submodule update --remote"] 207 | }, { 208 | "title": "Show all commits in the current branch yet to be merged to master", 209 | "tip": "git cherry -v master", 210 | "alternatives": ["git cherry -v master "] 211 | }, { 212 | "title": "Rename a branch", 213 | "tip": "git branch -m ", 214 | "alternatives": ["git branch -m [] "] 215 | }, { 216 | "title": "Rebases 'feature' to 'master' and merges it in to master ", 217 | "tip": "git rebase master feature && git checkout master && git merge -" 218 | }, { 219 | "title": "Archive the `master` branch", 220 | "tip": "git archive master --format=zip --output=master.zip" 221 | }, { 222 | "title": "Modify previous commit without modifying the commit message", 223 | "tip": "git add --all && git commit --amend --no-edit" 224 | }, { 225 | "title": "Prunes references to remove branches that have been deleted in the remote.", 226 | "tip": "git fetch -p", 227 | "alternatives": ["git remote prune origin"] 228 | }, { 229 | "title": "Delete local branches that has been squash and merged in the remote.", 230 | "tip": "git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D" 231 | }, { 232 | "title": "Retrieve the commit hash of the initial revision.", 233 | "tip": " git rev-list --reverse HEAD | head -1", 234 | "alternatives": ["git rev-list --max-parents=0 HEAD", "git log --pretty=oneline | tail -1 | cut -c 1-40", "git log --pretty=oneline --reverse | head -1 | cut -c 1-40"] 235 | }, { 236 | "title": "Visualize the version tree.", 237 | "tip": "git log --pretty=oneline --graph --decorate --all", 238 | "alternatives": ["gitk --all", "git log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d'"] 239 | }, { 240 | "title": "Visualize the tree including commits that are only referenced from reflogs", 241 | "tip": "git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all)" 242 | }, { 243 | "title": "Deploying git tracked subfolder to gh-pages", 244 | "tip": "git subtree push --prefix subfolder_name origin gh-pages", 245 | "alternatives": "git subtree push --prefix subfolder_name origin branch_name" 246 | }, { 247 | "title": "Adding a project to repo using subtree", 248 | "tip": "git subtree add --prefix=/ --squash git@github.com:/.git master" 249 | }, { 250 | "title": "Get latest changes in your repo for a linked project using subtree", 251 | "tip": "git subtree pull --prefix=/ --squash git@github.com:/.git master" 252 | }, { 253 | "title": "Export a branch with history to a file.", 254 | "tip": "git bundle create " 255 | }, { 256 | "title": "Import from a bundle", 257 | "tip": "git clone repo.bundle -b " 258 | }, { 259 | "title": "Get the name of current branch.", 260 | "tip": "git rev-parse --abbrev-ref HEAD" 261 | }, { 262 | "title": "Ignore one file on commit (e.g. Changelog).", 263 | "tip": "git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog" 264 | }, { 265 | "title": "Stash changes before rebasing", 266 | "tip": "git rebase --autostash" 267 | }, { 268 | "title": "Fetch pull request by ID to a local branch", 269 | "tip": "git fetch origin pull//head:", 270 | "alternatives": ["git pull origin pull//head:"] 271 | }, { 272 | "title": "Show the most recent tag on the current branch.", 273 | "tip": "git describe --tags --abbrev=0" 274 | }, { 275 | "title": "Show inline word diff.", 276 | "tip": "git diff --word-diff" 277 | }, { 278 | "title": "Show changes using common diff tools.", 279 | "tip": "git difftool [-t ] " 280 | }, { 281 | "title": "Don’t consider changes for tracked file.", 282 | "tip": "git update-index --assume-unchanged " 283 | }, { 284 | "title": "Undo assume-unchanged.", 285 | "tip": "git update-index --no-assume-unchanged " 286 | }, { 287 | "title": "Clean the files from `.gitignore`.", 288 | "tip": "git clean -X -f" 289 | }, { 290 | "title": "Restore deleted file.", 291 | "tip": "git checkout -- " 292 | }, { 293 | "title": "Restore file to a specific commit-hash", 294 | "tip": "git checkout -- " 295 | }, { 296 | "title": "Always rebase instead of merge on pull.", 297 | "tip": "git config --global pull.rebase true", 298 | "alternatives": ["#git < 1.7.9\ngit config --global branch.autosetuprebase always"] 299 | }, { 300 | "title": "List all the alias and configs.", 301 | "tip": "git config --list" 302 | }, { 303 | "title": "Make git case sensitive.", 304 | "tip": "git config --global core.ignorecase false" 305 | }, { 306 | "title": "Add custom editors.", 307 | "tip": "git config --global core.editor '$EDITOR'" 308 | }, { 309 | "title": "Auto correct typos.", 310 | "tip": "git config --global help.autocorrect 1" 311 | }, { 312 | "title": "Check if the change was a part of a release.", 313 | "tip": "git name-rev --name-only " 314 | }, { 315 | "title": "Dry run. (any command that supports dry-run flag should do.)", 316 | "tip": "git clean -fd --dry-run" 317 | }, { 318 | "title": "Marks your commit as a fix of a previous commit.", 319 | "tip": "git commit --fixup " 320 | }, { 321 | "title": "Squash fixup commits normal commits.", 322 | "tip": "git rebase -i --autosquash" 323 | }, { 324 | "title": "Skip staging area during commit.", 325 | "tip": "git commit --only " 326 | }, { 327 | "title": "Interactive staging.", 328 | "tip": "git add -i" 329 | }, { 330 | "title": "List ignored files.", 331 | "tip": "git check-ignore *" 332 | }, { 333 | "title": "Status of ignored files.", 334 | "tip": "git status --ignored" 335 | }, { 336 | "title": "Commits in Branch1 that are not in Branch2", 337 | "tip": "git log Branch1 ^Branch2" 338 | }, { 339 | "title": "List n last commits", 340 | "tip": "git log -", 341 | "alternatives": ["git log -n "] 342 | }, { 343 | "title": "Reuse recorded resolution, record and reuse previous conflicts resolutions.", 344 | "tip": "git config --global rerere.enabled 1" 345 | }, { 346 | "title": "Open all conflicted files in an editor.", 347 | "tip": "git diff --name-only | uniq | xargs $EDITOR" 348 | }, { 349 | "title": "Count unpacked number of objects and their disk consumption.", 350 | "tip": "git count-objects --human-readable" 351 | }, { 352 | "title": "Prune all unreachable objects from the object database.", 353 | "tip": "git gc --prune=now --aggressive" 354 | }, { 355 | "title": "Instantly browse your working repository in gitweb.", 356 | "tip": "git instaweb [--local] [--httpd=] [--port=] [--browser=]" 357 | }, { 358 | "title": "View the GPG signatures in the commit log", 359 | "tip": "git log --show-signature" 360 | }, { 361 | "title": "Remove entry in the global config.", 362 | "tip": "git config --global --unset " 363 | }, { 364 | "title": "Checkout a new branch without any history", 365 | "tip": "git checkout --orphan " 366 | }, { 367 | "title": "Extract file from another branch.", 368 | "tip": "git show :" 369 | }, { 370 | "title": "List only the root and merge commits.", 371 | "tip": "git log --first-parent" 372 | }, { 373 | "title": "Change previous two commits with an interactive rebase.", 374 | "tip": "git rebase --interactive HEAD~2" 375 | }, { 376 | "title": "List all branch is WIP", 377 | "tip": "git checkout master && git branch --no-merged" 378 | }, { 379 | "title": "Find guilty with binary search", 380 | "tip": "git 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" 381 | }, { 382 | "title": "Bypass pre-commit and commit-msg githooks", 383 | "tip": "git commit --no-verify" 384 | }, { 385 | "title": "List commits and changes to a specific file (even through renaming)", 386 | "tip": "git log --follow -p -- " 387 | }, { 388 | "title": "Clone a single branch", 389 | "tip": "git clone -b --single-branch https://github.com/user/repo.git" 390 | }, { 391 | "title": "Create and switch new branch", 392 | "tip": "git checkout -b ", 393 | "alternatives": ["git branch && git checkout ", "git switch -c "] 394 | }, { 395 | "title": "Ignore file mode changes on commits", 396 | "tip": "git config core.fileMode false" 397 | }, { 398 | "title": "Turn off git colored terminal output", 399 | "tip": "git config --global color.ui false" 400 | }, { 401 | "title": "Specific color settings", 402 | "tip": "git config --global " 403 | }, { 404 | "title": "Show all local branches ordered by recent commits", 405 | "tip": "git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/" 406 | }, { 407 | "title": "Find lines matching the pattern (regex or string) in tracked files", 408 | "tip": "git grep --heading --line-number 'foo bar'" 409 | }, { 410 | "title": "Clone a shallow copy of a repository", 411 | "tip": "git clone https://github.com/user/repo.git --depth 1" 412 | }, { 413 | "title": "Search Commit log across all branches for given text", 414 | "tip": "git log --all --grep=''" 415 | }, { 416 | "title": "Get first commit in a branch (from master)", 417 | "tip": "git log --oneline master.. | tail -1", 418 | "alternatives": ["git log --reverse master.. | head -6"] 419 | }, { 420 | "title": "Unstaging Staged file", 421 | "tip": "git reset HEAD " 422 | }, { 423 | "title": "Force push to Remote Repository", 424 | "tip": "git push -f " 425 | }, { 426 | "title": "Adding Remote name", 427 | "tip": "git remote add " 428 | }, { 429 | "title": "List all currently configured remotes", 430 | "tip": "git remote -v" 431 | }, { 432 | "title": "Show the author, time and last revision made to each line of a given file", 433 | "tip": "git blame " 434 | }, { 435 | "title": "Group commits by authors and title", 436 | "tip": "git shortlog" 437 | }, { 438 | "title": "Forced push but still ensure you don't overwrite other's work", 439 | "tip": "git push --force-with-lease " 440 | }, { 441 | "title": "Show how many lines does an author contribute", 442 | "tip": "git 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 }' -", 443 | "alternatives": ["git 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"] 444 | }, { 445 | "title": "Revert: Reverting an entire merge", 446 | "tip": "git revert -m 1 " 447 | }, { 448 | "title": "Number of commits in a branch", 449 | "tip": "git rev-list --count " 450 | }, { 451 | "title": "Alias: git undo", 452 | "tip": "git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'" 453 | }, { 454 | "title": "Add object notes", 455 | "tip": "git notes add -m 'Note on the previous commit....'" 456 | }, { 457 | "title": "Show all the git-notes", 458 | "tip": "git log --show-notes='*'" 459 | }, { 460 | "title": "Apply commit from another repository", 461 | "tip": "git --git-dir=/.git format-patch -k -1 --stdout | git am -3 -k" 462 | }, { 463 | "title": "Specific fetch reference", 464 | "tip": "git fetch origin master:refs/remotes/origin/mymaster" 465 | }, { 466 | "title": "Find common ancestor of two branches", 467 | "tip": "git merge-base " 468 | }, { 469 | "title": "List unpushed git commits", 470 | "tip": "git log --branches --not --remotes", 471 | "alternatives": ["git log @{u}..", "git cherry -v"] 472 | }, { 473 | "title": "Add everything, but whitespace changes", 474 | "tip": "git diff --ignore-all-space | git apply --cached" 475 | }, { 476 | "title": "Edit [local/global] git config", 477 | "tip": "git config [--global] --edit" 478 | }, { 479 | "title": "blame on certain range", 480 | "tip": "git blame -L ," 481 | }, { 482 | "title": "Show a Git logical variable.", 483 | "tip": "git var -l | " 484 | }, { 485 | "title": "Preformatted patch file.", 486 | "tip": "git format-patch -M upstream..topic" 487 | }, { 488 | "title": "Get the repo name.", 489 | "tip": "git rev-parse --show-toplevel" 490 | }, { 491 | "title": "logs between date range", 492 | "tip": "git log --since='FEB 1 2017' --until='FEB 14 2017'" 493 | }, { 494 | "title": "Exclude author from logs", 495 | "tip": "git log --perl-regexp --author='^((?!excluded-author-regex).*)$'" 496 | }, { 497 | "title": "Generates a summary of pending changes", 498 | "tip": "git request-pull v1.0 https://git.ko.xz/project master:for-linus" 499 | }, { 500 | "title": "List references in a remote repository", 501 | "tip": "git ls-remote git://git.kernel.org/pub/scm/git/git.git" 502 | }, { 503 | "title": "Backup untracked files.", 504 | "tip": "git ls-files --others -i --exclude-standard | xargs zip untracked.zip" 505 | }, { 506 | "title": "List all git aliases", 507 | "tip": "git config -l | grep alias | sed 's/^alias\\.//g'", 508 | "alternatives": ["git config -l | grep alias | cut -d '.' -f 2"] 509 | }, { 510 | "title": "Show git status short", 511 | "tip": "git status --short --branch" 512 | }, 513 | { 514 | "title": "Checkout a commit prior to a day ago", 515 | "tip": "git checkout master@{yesterday}" 516 | }, { 517 | "title": "Push the current branch to the same name on the remote repository", 518 | "tip": "git push origin HEAD" 519 | }, { 520 | "title": "Push a new local branch to remote repository and track", 521 | "tip": "git push -u origin " 522 | }, { 523 | "title": "Change a branch base", 524 | "tip": "git rebase --onto " 525 | }, { 526 | "title": "Use SSH instead of HTTPs for remotes", 527 | "tip": "git config --global url.'git@github.com:'.insteadOf 'https://github.com/'" 528 | }, { 529 | "title": "Update a submodule to the latest commit", 530 | "tip": "cd \ngit pull origin \ncd \ngit add \ngit commit -m \"submodule updated\"" 531 | }, { 532 | "title": "Prevent auto replacing LF with CRLF", 533 | "tip": "git config --global core.autocrlf false" 534 | } 535 | ] 536 | --------------------------------------------------------------------------------