├── .doxie.render.js ├── .doxie.render.toc.js ├── .gitignore ├── .vscode └── settings.json ├── 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 | } -------------------------------------------------------------------------------- /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) 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 | * [Delete local tag](#delete-local-tag) 36 | * [Delete remote tag](#delete-remote-tag) 37 | * [Undo local changes with the last content in head](#undo-local-changes-with-the-last-content-in-head) 38 | * [Revert: Undo a commit by creating a new commit](#revert-undo-a-commit-by-creating-a-new-commit) 39 | * [Reset: Discard commits, advised for private branch](#reset-discard-commits-advised-for-private-branch) 40 | * [Reword the previous commit message](#reword-the-previous-commit-message) 41 | * [See commit history for just the current branch](#see-commit-history-for-just-the-current-branch) 42 | * [Amend author.](#amend-author) 43 | * [Reset author, after author has been changed in the global config.](#reset-author-after-author-has-been-changed-in-the-global-config) 44 | * [Changing a remote's URL](#changing-a-remotes-url) 45 | * [Get list of all remote references](#get-list-of-all-remote-references) 46 | * [Get list of all local and remote branches](#get-list-of-all-local-and-remote-branches) 47 | * [Get only remote branches](#get-only-remote-branches) 48 | * [Stage parts of a changed file, instead of the entire file](#stage-parts-of-a-changed-file-instead-of-the-entire-file) 49 | * [Get git bash completion](#get-git-bash-completion) 50 | * [What changed since two weeks?](#what-changed-since-two-weeks) 51 | * [See all commits made since forking from master](#see-all-commits-made-since-forking-from-master) 52 | * [Pick commits across branches using cherry-pick](#pick-commits-across-branches-using-cherry-pick) 53 | * [Find out branches containing commit-hash](#find-out-branches-containing-commit-hash) 54 | * [Git Aliases](#git-aliases) 55 | * [Saving current state of tracked files without commiting](#saving-current-state-of-tracked-files-without-commiting) 56 | * [Saving current state of unstaged changes to tracked files](#saving-current-state-of-unstaged-changes-to-tracked-files) 57 | * [Saving current state including untracked files](#saving-current-state-including-untracked-files) 58 | * [Saving current state with message](#saving-current-state-with-message) 59 | * [Saving current state of all files (ignored, untracked, and tracked)](#saving-current-state-of-all-files-ignored-untracked-and-tracked) 60 | * [Show list of all saved stashes](#show-list-of-all-saved-stashes) 61 | * [Apply any stash without deleting from the stashed list](#apply-any-stash-without-deleting-from-the-stashed-list) 62 | * [Apply last stashed state and delete it from stashed list](#apply-last-stashed-state-and-delete-it-from-stashed-list) 63 | * [Delete all stored stashes](#delete-all-stored-stashes) 64 | * [Grab a single file from a stash](#grab-a-single-file-from-a-stash) 65 | * [Show all tracked files](#show-all-tracked-files) 66 | * [Show all untracked files](#show-all-untracked-files) 67 | * [Show all ignored files](#show-all-ignored-files) 68 | * [Create new working tree from a repository (git 2.5)](#create-new-working-tree-from-a-repository-git-25) 69 | * [Create new working tree from HEAD state](#create-new-working-tree-from-head-state) 70 | * [Untrack files without deleting](#untrack-files-without-deleting) 71 | * [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) 72 | * [Forcefully remove untracked files](#forcefully-remove-untracked-files) 73 | * [Forcefully remove untracked directory](#forcefully-remove-untracked-directory) 74 | * [Update all the submodules](#update-all-the-submodules) 75 | * [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) 76 | * [Rename a branch](#rename-a-branch) 77 | * [Rebases 'feature' to 'master' and merges it in to master ](#rebases-feature-to-master-and-merges-it-in-to-master) 78 | * [Archive the `master` branch](#archive-the-master-branch) 79 | * [Modify previous commit without modifying the commit message](#modify-previous-commit-without-modifying-the-commit-message) 80 | * [Prunes references to remote branches that have been deleted in the remote.](#prunes-references-to-remote-branches-that-have-been-deleted-in-the-remote) 81 | * [Retrieve the commit hash of the initial revision.](#retrieve-the-commit-hash-of-the-initial-revision) 82 | * [Visualize the version tree.](#visualize-the-version-tree) 83 | * [Visualize the tree including commits that are only referenced from reflogs](#visualize-the-tree-including-commits-that-are-only-referenced-from-reflogs) 84 | * [Deploying git tracked subfolder to gh-pages](#deploying-git-tracked-subfolder-to-gh-pages) 85 | * [Adding a project to repo using subtree](#adding-a-project-to-repo-using-subtree) 86 | * [Get latest changes in your repo for a linked project using subtree](#get-latest-changes-in-your-repo-for-a-linked-project-using-subtree) 87 | * [Export a branch with history to a file.](#export-a-branch-with-history-to-a-file) 88 | * [Import from a bundle](#import-from-a-bundle) 89 | * [Get the name of current branch.](#get-the-name-of-current-branch) 90 | * [Ignore one file on commit (e.g. Changelog).](#ignore-one-file-on-commit-eg-changelog) 91 | * [Stash changes before rebasing](#stash-changes-before-rebasing) 92 | * [Fetch pull request by ID to a local branch](#fetch-pull-request-by-id-to-a-local-branch) 93 | * [Show the most recent tag on the current branch.](#show-the-most-recent-tag-on-the-current-branch) 94 | * [Show inline word diff.](#show-inline-word-diff) 95 | * [Show changes using common diff tools.](#show-changes-using-common-diff-tools) 96 | * [Don’t consider changes for tracked file.](#dont-consider-changes-for-tracked-file) 97 | * [Undo assume-unchanged.](#undo-assume-unchanged) 98 | * [Clean the files from `.gitignore`.](#clean-the-files-from-gitignore) 99 | * [Restore deleted file.](#restore-deleted-file) 100 | * [Restore file to a specific commit-hash](#restore-file-to-a-specific-commit-hash) 101 | * [Always rebase instead of merge on pull.](#always-rebase-instead-of-merge-on-pull) 102 | * [List all the alias and configs.](#list-all-the-alias-and-configs) 103 | * [Make git case sensitive.](#make-git-case-sensitive) 104 | * [Add custom editors.](#add-custom-editors) 105 | * [Auto correct typos.](#auto-correct-typos) 106 | * [Check if the change was a part of a release.](#check-if-the-change-was-a-part-of-a-release) 107 | * [Dry run. (any command that supports dry-run flag should do.)](#dry-run-any-command-that-supports-dry-run-flag-should-do) 108 | * [Marks your commit as a fix of a previous commit.](#marks-your-commit-as-a-fix-of-a-previous-commit) 109 | * [Squash fixup commits normal commits.](#squash-fixup-commits-normal-commits) 110 | * [Skip staging area during commit.](#skip-staging-area-during-commit) 111 | * [Interactive staging.](#interactive-staging) 112 | * [List ignored files.](#list-ignored-files) 113 | * [Status of ignored files.](#status-of-ignored-files) 114 | * [Commits in Branch1 that are not in Branch2](#commits-in-branch1-that-are-not-in-branch2) 115 | * [List n last commits](#list-n-last-commits) 116 | * [Reuse recorded resolution, record and reuse previous conflicts resolutions.](#reuse-recorded-resolution-record-and-reuse-previous-conflicts-resolutions) 117 | * [Open all conflicted files in an editor.](#open-all-conflicted-files-in-an-editor) 118 | * [Count unpacked number of objects and their disk consumption.](#count-unpacked-number-of-objects-and-their-disk-consumption) 119 | * [Prune all unreachable objects from the object database.](#prune-all-unreachable-objects-from-the-object-database) 120 | * [Instantly browse your working repository in gitweb.](#instantly-browse-your-working-repository-in-gitweb) 121 | * [View the GPG signatures in the commit log](#view-the-gpg-signatures-in-the-commit-log) 122 | * [Remove entry in the global config.](#remove-entry-in-the-global-config) 123 | * [Checkout a new branch without any history](#checkout-a-new-branch-without-any-history) 124 | * [Extract file from another branch.](#extract-file-from-another-branch) 125 | * [List only the root and merge commits.](#list-only-the-root-and-merge-commits) 126 | * [Change previous two commits with an interactive rebase.](#change-previous-two-commits-with-an-interactive-rebase) 127 | * [List all branch is WIP](#list-all-branch-is-wip) 128 | * [Find guilty with binary search](#find-guilty-with-binary-search) 129 | * [Bypass pre-commit and commit-msg githooks](#bypass-pre-commit-and-commit-msg-githooks) 130 | * [List commits and changes to a specific file (even through renaming)](#list-commits-and-changes-to-a-specific-file-even-through-renaming) 131 | * [Clone a single branch](#clone-a-single-branch) 132 | * [Create and switch new branch](#create-and-switch-new-branch) 133 | * [Ignore file mode changes on commits](#ignore-file-mode-changes-on-commits) 134 | * [Turn off git colored terminal output](#turn-off-git-colored-terminal-output) 135 | * [Specific color settings](#specific-color-settings) 136 | * [Show all local branches ordered by recent commits](#show-all-local-branches-ordered-by-recent-commits) 137 | * [Find lines matching the pattern (regex or string) in tracked files](#find-lines-matching-the-pattern-regex-or-string-in-tracked-files) 138 | * [Clone a shallow copy of a repository](#clone-a-shallow-copy-of-a-repository) 139 | * [Search Commit log across all branches for given text](#search-commit-log-across-all-branches-for-given-text) 140 | * [Get first commit in a branch (from master)](#get-first-commit-in-a-branch-from-master) 141 | * [Unstaging Staged file](#unstaging-staged-file) 142 | * [Force push to Remote Repository](#force-push-to-remote-repository) 143 | * [Adding Remote name](#adding-remote-name) 144 | * [List all currently configured remotes](#list-all-currently-configured-remotes) 145 | * [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) 146 | * [Group commits by authors and title](#group-commits-by-authors-and-title) 147 | * [Forced push but still ensure you don't overwrite other's work](#forced-push-but-still-ensure-you-dont-overwrite-others-work) 148 | * [Show how many lines does an author contribute](#show-how-many-lines-does-an-author-contribute) 149 | * [Revert: Reverting an entire merge](#revert-reverting-an-entire-merge) 150 | * [Number of commits in a branch](#number-of-commits-in-a-branch) 151 | * [Alias: git undo](#alias-git-undo) 152 | * [Add object notes](#add-object-notes) 153 | * [Show all the git-notes](#show-all-the-git-notes) 154 | * [Apply commit from another repository](#apply-commit-from-another-repository) 155 | * [Specific fetch reference](#specific-fetch-reference) 156 | * [Find common ancestor of two branches](#find-common-ancestor-of-two-branches) 157 | * [List unpushed git commits](#list-unpushed-git-commits) 158 | * [Add everything, but whitespace changes](#add-everything-but-whitespace-changes) 159 | * [Edit [local/global] git config](#edit-localglobal-git-config) 160 | * [blame on certain range](#blame-on-certain-range) 161 | * [Show a Git logical variable.](#show-a-git-logical-variable) 162 | * [Preformatted patch file.](#preformatted-patch-file) 163 | * [Get the repo name.](#get-the-repo-name) 164 | * [logs between date range](#logs-between-date-range) 165 | * [Exclude author from logs](#exclude-author-from-logs) 166 | * [Generates a summary of pending changes](#generates-a-summary-of-pending-changes) 167 | * [List references in a remote repository](#list-references-in-a-remote-repository) 168 | * [Backup untracked files.](#backup-untracked-files) 169 | * [List all git aliases](#list-all-git-aliases) 170 | * [Show git status short](#show-git-status-short) 171 | * [Checkout a commit prior to a day ago](#checkout-a-commit-prior-to-a-day-ago) 172 | * [Push a new local branch to remote repository and track](#push-a-new-local-branch-to-remote-repository-and-track) 173 | * [Change a branch base](#change-a-branch-base) 174 | * [Use SSH instead of HTTPs for remotes](#use-ssh-instead-of-https-for-remotes) 175 | * [Update a submodule to the latest commit](#update-a-submodule-to-the-latest-commit) 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | ## Everyday Git in twenty commands or so 184 | ```sh 185 | git help everyday 186 | ``` 187 | 188 | ## Show helpful guides that come with Git 189 | ```sh 190 | git help -g 191 | ``` 192 | 193 | ## Search change by content 194 | ```sh 195 | git log -S'' 196 | ``` 197 | 198 | ## Show changes over time for specific file 199 | ```sh 200 | git log -p 201 | ``` 202 | 203 | ## Remove sensitive data from history, after a push 204 | ```sh 205 | git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all 206 | ``` 207 | 208 | ## Sync with remote, overwrite local changes 209 | ```sh 210 | git fetch origin && git reset --hard origin/master && git clean -f -d 211 | ``` 212 | 213 | ## List of all files till a commit 214 | ```sh 215 | git ls-tree --name-only -r 216 | ``` 217 | 218 | ## Git reset first commit 219 | ```sh 220 | git update-ref -d HEAD 221 | ``` 222 | 223 | ## Reset: preserve uncommitted local changes 224 | ```sh 225 | git reset --keep 226 | ``` 227 | 228 | ## List all the conflicted files 229 | ```sh 230 | git diff --name-only --diff-filter=U 231 | ``` 232 | 233 | ## List of all files changed in a commit 234 | ```sh 235 | git diff-tree --no-commit-id --name-only -r 236 | ``` 237 | 238 | ## Unstaged changes since last commit 239 | ```sh 240 | git diff 241 | ``` 242 | 243 | ## Changes staged for commit 244 | ```sh 245 | git diff --cached 246 | ``` 247 | 248 | 249 | __Alternatives:__ 250 | ```sh 251 | git diff --staged 252 | ``` 253 | 254 | ## Show both staged and unstaged changes 255 | ```sh 256 | git diff HEAD 257 | ``` 258 | 259 | ## List all branches that are already merged into master 260 | ```sh 261 | git branch --merged master 262 | ``` 263 | 264 | ## Quickly switch to the previous branch 265 | ```sh 266 | git checkout - 267 | ``` 268 | 269 | 270 | __Alternatives:__ 271 | ```sh 272 | git checkout @{-1} 273 | ``` 274 | 275 | ## Remove branches that have already been merged with master 276 | ```sh 277 | git branch --merged master | grep -v '^\*' | xargs -n 1 git branch -d 278 | ``` 279 | 280 | 281 | __Alternatives:__ 282 | ```sh 283 | git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d # will not delete master if master is not checked out 284 | ``` 285 | 286 | ## List all branches and their upstreams, as well as last commit on branch 287 | ```sh 288 | git branch -vv 289 | ``` 290 | 291 | ## Track upstream branch 292 | ```sh 293 | git branch -u origin/mybranch 294 | ``` 295 | 296 | ## Delete local branch 297 | ```sh 298 | git branch -d 299 | ``` 300 | 301 | ## Delete remote branch 302 | ```sh 303 | git push origin --delete 304 | ``` 305 | 306 | 307 | __Alternatives:__ 308 | ```sh 309 | git push origin : 310 | ``` 311 | 312 | 313 | ```sh 314 | git branch -dr 315 | ``` 316 | 317 | ## Delete local tag 318 | ```sh 319 | git tag -d 320 | ``` 321 | 322 | ## Delete remote tag 323 | ```sh 324 | git push origin :refs/tags/ 325 | ``` 326 | 327 | ## Undo local changes with the last content in head 328 | ```sh 329 | git checkout -- 330 | ``` 331 | 332 | ## Revert: Undo a commit by creating a new commit 333 | ```sh 334 | git revert 335 | ``` 336 | 337 | ## Reset: Discard commits, advised for private branch 338 | ```sh 339 | git reset 340 | ``` 341 | 342 | ## Reword the previous commit message 343 | ```sh 344 | git commit -v --amend 345 | ``` 346 | 347 | ## See commit history for just the current branch 348 | ```sh 349 | git cherry -v master 350 | ``` 351 | 352 | ## Amend author. 353 | ```sh 354 | git commit --amend --author='Author Name ' 355 | ``` 356 | 357 | ## Reset author, after author has been changed in the global config. 358 | ```sh 359 | git commit --amend --reset-author --no-edit 360 | ``` 361 | 362 | ## Changing a remote's URL 363 | ```sh 364 | git remote set-url origin 365 | ``` 366 | 367 | ## Get list of all remote references 368 | ```sh 369 | git remote 370 | ``` 371 | 372 | 373 | __Alternatives:__ 374 | ```sh 375 | git remote show 376 | ``` 377 | 378 | ## Get list of all local and remote branches 379 | ```sh 380 | git branch -a 381 | ``` 382 | 383 | ## Get only remote branches 384 | ```sh 385 | git branch -r 386 | ``` 387 | 388 | ## Stage parts of a changed file, instead of the entire file 389 | ```sh 390 | git add -p 391 | ``` 392 | 393 | ## Get git bash completion 394 | ```sh 395 | curl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc 396 | ``` 397 | 398 | ## What changed since two weeks? 399 | ```sh 400 | git log --no-merges --raw --since='2 weeks ago' 401 | ``` 402 | 403 | 404 | __Alternatives:__ 405 | ```sh 406 | git whatchanged --since='2 weeks ago' 407 | ``` 408 | 409 | ## See all commits made since forking from master 410 | ```sh 411 | git log --no-merges --stat --reverse master.. 412 | ``` 413 | 414 | ## Pick commits across branches using cherry-pick 415 | ```sh 416 | git checkout && git cherry-pick 417 | ``` 418 | 419 | ## Find out branches containing commit-hash 420 | ```sh 421 | git branch -a --contains 422 | ``` 423 | 424 | 425 | __Alternatives:__ 426 | ```sh 427 | git branch --contains 428 | ``` 429 | 430 | ## Git Aliases 431 | ```sh 432 | git config --global alias. 433 | git config --global alias.st status 434 | ``` 435 | 436 | ## Saving current state of tracked files without commiting 437 | ```sh 438 | git stash 439 | ``` 440 | 441 | 442 | __Alternatives:__ 443 | ```sh 444 | git stash save 445 | ``` 446 | 447 | ## Saving current state of unstaged changes to tracked files 448 | ```sh 449 | git stash -k 450 | ``` 451 | 452 | 453 | __Alternatives:__ 454 | ```sh 455 | git stash --keep-index 456 | ``` 457 | 458 | 459 | ```sh 460 | git stash save --keep-index 461 | ``` 462 | 463 | ## Saving current state including untracked files 464 | ```sh 465 | git stash -u 466 | ``` 467 | 468 | 469 | __Alternatives:__ 470 | ```sh 471 | git stash save -u 472 | ``` 473 | 474 | 475 | ```sh 476 | git stash save --include-untracked 477 | ``` 478 | 479 | ## Saving current state with message 480 | ```sh 481 | git stash save 482 | ``` 483 | 484 | ## Saving current state of all files (ignored, untracked, and tracked) 485 | ```sh 486 | git stash -a 487 | ``` 488 | 489 | 490 | __Alternatives:__ 491 | ```sh 492 | git stash --all 493 | ``` 494 | 495 | 496 | ```sh 497 | git stash save --all 498 | ``` 499 | 500 | ## Show list of all saved stashes 501 | ```sh 502 | git stash list 503 | ``` 504 | 505 | ## Apply any stash without deleting from the stashed list 506 | ```sh 507 | git stash apply 508 | ``` 509 | 510 | ## Apply last stashed state and delete it from stashed list 511 | ```sh 512 | git stash pop 513 | ``` 514 | 515 | 516 | __Alternatives:__ 517 | ```sh 518 | git stash apply stash@{0} && git stash drop stash@{0} 519 | ``` 520 | 521 | ## Delete all stored stashes 522 | ```sh 523 | git stash clear 524 | ``` 525 | 526 | 527 | __Alternatives:__ 528 | ```sh 529 | git stash drop 530 | ``` 531 | 532 | ## Grab a single file from a stash 533 | ```sh 534 | git checkout -- 535 | ``` 536 | 537 | 538 | __Alternatives:__ 539 | ```sh 540 | git checkout stash@{0} -- 541 | ``` 542 | 543 | ## Show all tracked files 544 | ```sh 545 | git ls-files -t 546 | ``` 547 | 548 | ## Show all untracked files 549 | ```sh 550 | git ls-files --others 551 | ``` 552 | 553 | ## Show all ignored files 554 | ```sh 555 | git ls-files --others -i --exclude-standard 556 | ``` 557 | 558 | ## Create new working tree from a repository (git 2.5) 559 | ```sh 560 | git worktree add -b 561 | ``` 562 | 563 | ## Create new working tree from HEAD state 564 | ```sh 565 | git worktree add --detach HEAD 566 | ``` 567 | 568 | ## Untrack files without deleting 569 | ```sh 570 | git rm --cached 571 | ``` 572 | 573 | 574 | __Alternatives:__ 575 | ```sh 576 | git rm --cached -r 577 | ``` 578 | 579 | ## Before deleting untracked files/directory, do a dry run to get the list of these files/directories 580 | ```sh 581 | git clean -n 582 | ``` 583 | 584 | ## Forcefully remove untracked files 585 | ```sh 586 | git clean -f 587 | ``` 588 | 589 | ## Forcefully remove untracked directory 590 | ```sh 591 | git clean -f -d 592 | ``` 593 | 594 | ## Update all the submodules 595 | ```sh 596 | git submodule foreach git pull 597 | ``` 598 | 599 | 600 | __Alternatives:__ 601 | ```sh 602 | git submodule update --init --recursive 603 | ``` 604 | 605 | 606 | ```sh 607 | git submodule update --remote 608 | ``` 609 | 610 | ## Show all commits in the current branch yet to be merged to master 611 | ```sh 612 | git cherry -v master 613 | ``` 614 | 615 | 616 | __Alternatives:__ 617 | ```sh 618 | git cherry -v master 619 | ``` 620 | 621 | ## Rename a branch 622 | ```sh 623 | git branch -m 624 | ``` 625 | 626 | 627 | __Alternatives:__ 628 | ```sh 629 | git branch -m [] 630 | ``` 631 | 632 | ## Rebases 'feature' to 'master' and merges it in to master 633 | ```sh 634 | git rebase master feature && git checkout master && git merge - 635 | ``` 636 | 637 | ## Archive the `master` branch 638 | ```sh 639 | git archive master --format=zip --output=master.zip 640 | ``` 641 | 642 | ## Modify previous commit without modifying the commit message 643 | ```sh 644 | git add --all && git commit --amend --no-edit 645 | ``` 646 | 647 | ## Prunes references to remote branches that have been deleted in the remote. 648 | ```sh 649 | git fetch -p 650 | ``` 651 | 652 | 653 | __Alternatives:__ 654 | ```sh 655 | git remote prune origin 656 | ``` 657 | 658 | ## Retrieve the commit hash of the initial revision. 659 | ```sh 660 | git rev-list --reverse HEAD | head -1 661 | ``` 662 | 663 | 664 | __Alternatives:__ 665 | ```sh 666 | git rev-list --max-parents=0 HEAD 667 | ``` 668 | 669 | 670 | ```sh 671 | git log --pretty=oneline | tail -1 | cut -c 1-40 672 | ``` 673 | 674 | 675 | ```sh 676 | git log --pretty=oneline --reverse | head -1 | cut -c 1-40 677 | ``` 678 | 679 | ## Visualize the version tree. 680 | ```sh 681 | git log --pretty=oneline --graph --decorate --all 682 | ``` 683 | 684 | 685 | __Alternatives:__ 686 | ```sh 687 | gitk --all 688 | ``` 689 | 690 | 691 | ```sh 692 | git log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d' 693 | ``` 694 | 695 | ## Visualize the tree including commits that are only referenced from reflogs 696 | ```sh 697 | git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all) 698 | ``` 699 | 700 | ## Deploying git tracked subfolder to gh-pages 701 | ```sh 702 | git subtree push --prefix subfolder_name origin gh-pages 703 | ``` 704 | 705 | ## Adding a project to repo using subtree 706 | ```sh 707 | git subtree add --prefix=/ --squash git@github.com:/.git master 708 | ``` 709 | 710 | ## Get latest changes in your repo for a linked project using subtree 711 | ```sh 712 | git subtree pull --prefix=/ --squash git@github.com:/.git master 713 | ``` 714 | 715 | ## Export a branch with history to a file. 716 | ```sh 717 | git bundle create 718 | ``` 719 | 720 | ## Import from a bundle 721 | ```sh 722 | git clone repo.bundle -b 723 | ``` 724 | 725 | ## Get the name of current branch. 726 | ```sh 727 | git rev-parse --abbrev-ref HEAD 728 | ``` 729 | 730 | ## Ignore one file on commit (e.g. Changelog). 731 | ```sh 732 | git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog 733 | ``` 734 | 735 | ## Stash changes before rebasing 736 | ```sh 737 | git rebase --autostash 738 | ``` 739 | 740 | ## Fetch pull request by ID to a local branch 741 | ```sh 742 | git fetch origin pull//head: 743 | ``` 744 | 745 | 746 | __Alternatives:__ 747 | ```sh 748 | git pull origin pull//head: 749 | ``` 750 | 751 | ## Show the most recent tag on the current branch. 752 | ```sh 753 | git describe --tags --abbrev=0 754 | ``` 755 | 756 | ## Show inline word diff. 757 | ```sh 758 | git diff --word-diff 759 | ``` 760 | 761 | ## Show changes using common diff tools. 762 | ```sh 763 | git difftool [-t ] 764 | ``` 765 | 766 | ## Don’t consider changes for tracked file. 767 | ```sh 768 | git update-index --assume-unchanged 769 | ``` 770 | 771 | ## Undo assume-unchanged. 772 | ```sh 773 | git update-index --no-assume-unchanged 774 | ``` 775 | 776 | ## Clean the files from `.gitignore`. 777 | ```sh 778 | git clean -X -f 779 | ``` 780 | 781 | ## Restore deleted file. 782 | ```sh 783 | git checkout ^ -- 784 | ``` 785 | 786 | ## Restore file to a specific commit-hash 787 | ```sh 788 | git checkout -- 789 | ``` 790 | 791 | ## Always rebase instead of merge on pull. 792 | ```sh 793 | git config --global pull.rebase true 794 | ``` 795 | 796 | 797 | __Alternatives:__ 798 | ```sh 799 | #git < 1.7.9 800 | git config --global branch.autosetuprebase always 801 | ``` 802 | 803 | ## List all the alias and configs. 804 | ```sh 805 | git config --list 806 | ``` 807 | 808 | ## Make git case sensitive. 809 | ```sh 810 | git config --global core.ignorecase false 811 | ``` 812 | 813 | ## Add custom editors. 814 | ```sh 815 | git config --global core.editor '$EDITOR' 816 | ``` 817 | 818 | ## Auto correct typos. 819 | ```sh 820 | git config --global help.autocorrect 1 821 | ``` 822 | 823 | ## Check if the change was a part of a release. 824 | ```sh 825 | git name-rev --name-only 826 | ``` 827 | 828 | ## Dry run. (any command that supports dry-run flag should do.) 829 | ```sh 830 | git clean -fd --dry-run 831 | ``` 832 | 833 | ## Marks your commit as a fix of a previous commit. 834 | ```sh 835 | git commit --fixup 836 | ``` 837 | 838 | ## Squash fixup commits normal commits. 839 | ```sh 840 | git rebase -i --autosquash 841 | ``` 842 | 843 | ## Skip staging area during commit. 844 | ```sh 845 | git commit --only 846 | ``` 847 | 848 | ## Interactive staging. 849 | ```sh 850 | git add -i 851 | ``` 852 | 853 | ## List ignored files. 854 | ```sh 855 | git check-ignore * 856 | ``` 857 | 858 | ## Status of ignored files. 859 | ```sh 860 | git status --ignored 861 | ``` 862 | 863 | ## Commits in Branch1 that are not in Branch2 864 | ```sh 865 | git log Branch1 ^Branch2 866 | ``` 867 | 868 | ## List n last commits 869 | ```sh 870 | git log - 871 | ``` 872 | 873 | 874 | __Alternatives:__ 875 | ```sh 876 | git log -n 877 | ``` 878 | 879 | ## Reuse recorded resolution, record and reuse previous conflicts resolutions. 880 | ```sh 881 | git config --global rerere.enabled 1 882 | ``` 883 | 884 | ## Open all conflicted files in an editor. 885 | ```sh 886 | git diff --name-only | uniq | xargs $EDITOR 887 | ``` 888 | 889 | ## Count unpacked number of objects and their disk consumption. 890 | ```sh 891 | git count-objects --human-readable 892 | ``` 893 | 894 | ## Prune all unreachable objects from the object database. 895 | ```sh 896 | git gc --prune=now --aggressive 897 | ``` 898 | 899 | ## Instantly browse your working repository in gitweb. 900 | ```sh 901 | git instaweb [--local] [--httpd=] [--port=] [--browser=] 902 | ``` 903 | 904 | ## View the GPG signatures in the commit log 905 | ```sh 906 | git log --show-signature 907 | ``` 908 | 909 | ## Remove entry in the global config. 910 | ```sh 911 | git config --global --unset 912 | ``` 913 | 914 | ## Checkout a new branch without any history 915 | ```sh 916 | git checkout --orphan 917 | ``` 918 | 919 | ## Extract file from another branch. 920 | ```sh 921 | git show : 922 | ``` 923 | 924 | ## List only the root and merge commits. 925 | ```sh 926 | git log --first-parent 927 | ``` 928 | 929 | ## Change previous two commits with an interactive rebase. 930 | ```sh 931 | git rebase --interactive HEAD~2 932 | ``` 933 | 934 | ## List all branch is WIP 935 | ```sh 936 | git checkout master && git branch --no-merged 937 | ``` 938 | 939 | ## Find guilty with binary search 940 | ```sh 941 | git bisect start # Search start 942 | git bisect bad # Set point to bad commit 943 | git bisect good v2.6.13-rc2 # Set point to good commit|tag 944 | git bisect bad # Say current state is bad 945 | git bisect good # Say current state is good 946 | git bisect reset # Finish search 947 | 948 | ``` 949 | 950 | ## Bypass pre-commit and commit-msg githooks 951 | ```sh 952 | git commit --no-verify 953 | ``` 954 | 955 | ## List commits and changes to a specific file (even through renaming) 956 | ```sh 957 | git log --follow -p -- 958 | ``` 959 | 960 | ## Clone a single branch 961 | ```sh 962 | git clone -b --single-branch https://github.com/user/repo.git 963 | ``` 964 | 965 | ## Create and switch new branch 966 | ```sh 967 | git checkout -b 968 | ``` 969 | 970 | 971 | __Alternatives:__ 972 | ```sh 973 | git branch && git checkout 974 | ``` 975 | 976 | ## Ignore file mode changes on commits 977 | ```sh 978 | git config core.fileMode false 979 | ``` 980 | 981 | ## Turn off git colored terminal output 982 | ```sh 983 | git config --global color.ui false 984 | ``` 985 | 986 | ## Specific color settings 987 | ```sh 988 | git config --global 989 | ``` 990 | 991 | ## Show all local branches ordered by recent commits 992 | ```sh 993 | git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ 994 | ``` 995 | 996 | ## Find lines matching the pattern (regex or string) in tracked files 997 | ```sh 998 | git grep --heading --line-number 'foo bar' 999 | ``` 1000 | 1001 | ## Clone a shallow copy of a repository 1002 | ```sh 1003 | git clone https://github.com/user/repo.git --depth 1 1004 | ``` 1005 | 1006 | ## Search Commit log across all branches for given text 1007 | ```sh 1008 | git log --all --grep='' 1009 | ``` 1010 | 1011 | ## Get first commit in a branch (from master) 1012 | ```sh 1013 | git log --oneline master.. | tail -1 1014 | ``` 1015 | 1016 | 1017 | __Alternatives:__ 1018 | ```sh 1019 | git log --reverse master.. | head -6 1020 | ``` 1021 | 1022 | ## Unstaging Staged file 1023 | ```sh 1024 | git reset HEAD 1025 | ``` 1026 | 1027 | ## Force push to Remote Repository 1028 | ```sh 1029 | git push -f 1030 | ``` 1031 | 1032 | ## Adding Remote name 1033 | ```sh 1034 | git remote add 1035 | ``` 1036 | 1037 | ## List all currently configured remotes 1038 | ```sh 1039 | git remote -v 1040 | ``` 1041 | 1042 | ## Show the author, time and last revision made to each line of a given file 1043 | ```sh 1044 | git blame 1045 | ``` 1046 | 1047 | ## Group commits by authors and title 1048 | ```sh 1049 | git shortlog 1050 | ``` 1051 | 1052 | ## Forced push but still ensure you don't overwrite other's work 1053 | ```sh 1054 | git push --force-with-lease 1055 | ``` 1056 | 1057 | ## Show how many lines does an author contribute 1058 | ```sh 1059 | git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | gawk '{ add += ; subs += ; loc += - } END { printf "added lines: %s removed lines: %s total lines: %s 1060 | ", add, subs, loc }' - 1061 | ``` 1062 | 1063 | 1064 | __Alternatives:__ 1065 | ```sh 1066 | git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | awk '{ add += ; subs += ; loc += - } END { printf "added lines: %s, removed lines: %s, total lines: %s 1067 | ", add, subs, loc }' - # on Mac OSX 1068 | ``` 1069 | 1070 | ## Revert: Reverting an entire merge 1071 | ```sh 1072 | git revert -m 1 1073 | ``` 1074 | 1075 | ## Number of commits in a branch 1076 | ```sh 1077 | git rev-list --count 1078 | ``` 1079 | 1080 | ## Alias: git undo 1081 | ```sh 1082 | git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f' 1083 | ``` 1084 | 1085 | ## Add object notes 1086 | ```sh 1087 | git notes add -m 'Note on the previous commit....' 1088 | ``` 1089 | 1090 | ## Show all the git-notes 1091 | ```sh 1092 | git log --show-notes='*' 1093 | ``` 1094 | 1095 | ## Apply commit from another repository 1096 | ```sh 1097 | git --git-dir=/.git format-patch -k -1 --stdout | git am -3 -k 1098 | ``` 1099 | 1100 | ## Specific fetch reference 1101 | ```sh 1102 | git fetch origin master:refs/remotes/origin/mymaster 1103 | ``` 1104 | 1105 | ## Find common ancestor of two branches 1106 | ```sh 1107 | git merge-base 1108 | ``` 1109 | 1110 | ## List unpushed git commits 1111 | ```sh 1112 | git log --branches --not --remotes 1113 | ``` 1114 | 1115 | 1116 | __Alternatives:__ 1117 | ```sh 1118 | git log @{u}.. 1119 | ``` 1120 | 1121 | 1122 | ```sh 1123 | git cherry -v 1124 | ``` 1125 | 1126 | ## Add everything, but whitespace changes 1127 | ```sh 1128 | git diff --ignore-all-space | git apply --cached 1129 | ``` 1130 | 1131 | ## Edit [local/global] git config 1132 | ```sh 1133 | git config [--global] --edit 1134 | ``` 1135 | 1136 | ## blame on certain range 1137 | ```sh 1138 | git blame -L , 1139 | ``` 1140 | 1141 | ## Show a Git logical variable. 1142 | ```sh 1143 | git var -l | 1144 | ``` 1145 | 1146 | ## Preformatted patch file. 1147 | ```sh 1148 | git format-patch -M upstream..topic 1149 | ``` 1150 | 1151 | ## Get the repo name. 1152 | ```sh 1153 | git rev-parse --show-toplevel 1154 | ``` 1155 | 1156 | ## logs between date range 1157 | ```sh 1158 | git log --since='FEB 1 2017' --until='FEB 14 2017' 1159 | ``` 1160 | 1161 | ## Exclude author from logs 1162 | ```sh 1163 | git log --perl-regexp --author='^((?!excluded-author-regex).*) 1164 | 1165 | ``` 1166 | 1167 | ## Generates a summary of pending changes 1168 | ```sh 1169 | git request-pull v1.0 https://git.ko.xz/project master:for-linus 1170 | ``` 1171 | 1172 | ## List references in a remote repository 1173 | ```sh 1174 | git ls-remote git://git.kernel.org/pub/scm/git/git.git 1175 | ``` 1176 | 1177 | ## Backup untracked files. 1178 | ```sh 1179 | git ls-files --others -i --exclude-standard | xargs zip untracked.zip 1180 | ``` 1181 | 1182 | ## List all git aliases 1183 | ```sh 1184 | git config -l | grep alias | sed 's/^alias\.//g' 1185 | ``` 1186 | 1187 | 1188 | __Alternatives:__ 1189 | ```sh 1190 | git config -l | grep alias | cut -d '.' -f 2 1191 | ``` 1192 | 1193 | ## Show git status short 1194 | ```sh 1195 | git status --short --branch 1196 | ``` 1197 | 1198 | ## Checkout a commit prior to a day ago 1199 | ```sh 1200 | git checkout master@{yesterday} 1201 | ``` 1202 | 1203 | ## Push a new local branch to remote repository and track 1204 | ```sh 1205 | git push -u origin 1206 | ``` 1207 | 1208 | ## Change a branch base 1209 | ```sh 1210 | git rebase --onto 1211 | ``` 1212 | 1213 | ## Use SSH instead of HTTPs for remotes 1214 | ```sh 1215 | git config --global url.'git@github.com:'.insteadOf 'https://github.com/' 1216 | ``` 1217 | 1218 | ## Update a submodule to the latest commit 1219 | ```sh 1220 | cd 1221 | git pull origin 1222 | cd 1223 | git add 1224 | git commit -m "submodule updated" 1225 | ``` 1226 | 1227 | 1228 | 1229 | -------------------------------------------------------------------------------- /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": "0.8.1", 219 | "resolved": "https://registry.npmjs.org/husky/-/husky-0.8.1.tgz", 220 | "integrity": "sha1-7MeXuMTGiToz9IcDvJeppeUNhg8=", 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": "^0.8.1" 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": "Delete local tag", 70 | "tip": "git tag -d " 71 | }, { 72 | "title": "Delete remote tag", 73 | "tip": "git push origin :refs/tags/" 74 | }, { 75 | "title": "Undo local changes with the last content in head", 76 | "tip": "git checkout -- " 77 | }, { 78 | "title": "Revert: Undo a commit by creating a new commit", 79 | "tip": "git revert " 80 | }, { 81 | "title": "Reset: Discard commits, advised for private branch", 82 | "tip": "git reset " 83 | }, { 84 | "title": "Reword the previous commit message", 85 | "tip": "git commit -v --amend" 86 | }, { 87 | "title": "See commit history for just the current branch", 88 | "tip": "git cherry -v master" 89 | }, { 90 | "title": "Amend author.", 91 | "tip": "git commit --amend --author='Author Name '" 92 | }, { 93 | "title": "Reset author, after author has been changed in the global config.", 94 | "tip": "git commit --amend --reset-author --no-edit" 95 | }, { 96 | "title": "Changing a remote's URL", 97 | "tip": "git remote set-url origin " 98 | }, { 99 | "title": "Get list of all remote references", 100 | "tip": "git remote", 101 | "alternatives": ["git remote show"] 102 | }, { 103 | "title": "Get list of all local and remote branches", 104 | "tip": "git branch -a" 105 | }, { 106 | "title": "Get only remote branches", 107 | "tip": "git branch -r" 108 | }, { 109 | "title": "Stage parts of a changed file, instead of the entire file", 110 | "tip": "git add -p" 111 | }, { 112 | "title": "Get git bash completion", 113 | "tip": "curl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc" 114 | }, { 115 | "title": "What changed since two weeks?", 116 | "tip": "git log --no-merges --raw --since='2 weeks ago'", 117 | "alternatives": ["git whatchanged --since='2 weeks ago'"] 118 | }, { 119 | "title": "See all commits made since forking from master", 120 | "tip": "git log --no-merges --stat --reverse master.." 121 | }, { 122 | "title": "Pick commits across branches using cherry-pick", 123 | "tip": "git checkout && git cherry-pick " 124 | }, { 125 | "title": "Find out branches containing commit-hash", 126 | "tip": "git branch -a --contains ", 127 | "alternatives": ["git branch --contains "] 128 | }, { 129 | "title": "Git Aliases", 130 | "tip": "git config --global alias. \ngit config --global alias.st status" 131 | }, { 132 | "title": "Saving current state of tracked files without commiting", 133 | "tip": "git stash", 134 | "alternatives": ["git stash save"] 135 | }, { 136 | "title": "Saving current state of unstaged changes to tracked files", 137 | "tip": "git stash -k", 138 | "alternatives": ["git stash --keep-index", "git stash save --keep-index"] 139 | }, { 140 | "title": "Saving current state including untracked files", 141 | "tip": "git stash -u", 142 | "alternatives": ["git stash save -u", "git stash save --include-untracked"] 143 | }, { 144 | "title": "Saving current state with message", 145 | "tip": "git stash save " 146 | }, { 147 | "title": "Saving current state of all files (ignored, untracked, and tracked)", 148 | "tip": "git stash -a", 149 | "alternatives": ["git stash --all", "git stash save --all"] 150 | }, { 151 | "title": "Show list of all saved stashes", 152 | "tip": "git stash list" 153 | }, { 154 | "title": "Apply any stash without deleting from the stashed list", 155 | "tip": "git stash apply " 156 | }, { 157 | "title": "Apply last stashed state and delete it from stashed list", 158 | "tip": "git stash pop", 159 | "alternatives": ["git stash apply stash@{0} && git stash drop stash@{0}"] 160 | }, { 161 | "title": "Delete all stored stashes", 162 | "tip": "git stash clear", 163 | "alternatives": ["git stash drop "] 164 | }, { 165 | "title": "Grab a single file from a stash", 166 | "tip": "git checkout -- ", 167 | "alternatives": ["git checkout stash@{0} -- "] 168 | }, { 169 | "title": "Show all tracked files", 170 | "tip": "git ls-files -t" 171 | }, { 172 | "title": "Show all untracked files", 173 | "tip": "git ls-files --others" 174 | }, { 175 | "title": "Show all ignored files", 176 | "tip": "git ls-files --others -i --exclude-standard" 177 | }, { 178 | "title": "Create new working tree from a repository (git 2.5)", 179 | "tip": "git worktree add -b " 180 | }, { 181 | "title": "Create new working tree from HEAD state", 182 | "tip": "git worktree add --detach HEAD" 183 | }, { 184 | "title": "Untrack files without deleting", 185 | "tip": "git rm --cached ", 186 | "alternatives": ["git rm --cached -r "] 187 | }, { 188 | "title": "Before deleting untracked files/directory, do a dry run to get the list of these files/directories", 189 | "tip": "git clean -n" 190 | }, { 191 | "title": "Forcefully remove untracked files", 192 | "tip": "git clean -f" 193 | }, { 194 | "title": "Forcefully remove untracked directory", 195 | "tip": "git clean -f -d" 196 | }, { 197 | "title": "Update all the submodules", 198 | "tip": "git submodule foreach git pull", 199 | "alternatives": ["git submodule update --init --recursive", "git submodule update --remote"] 200 | }, { 201 | "title": "Show all commits in the current branch yet to be merged to master", 202 | "tip": "git cherry -v master", 203 | "alternatives": ["git cherry -v master "] 204 | }, { 205 | "title": "Rename a branch", 206 | "tip": "git branch -m ", 207 | "alternatives": ["git branch -m [] "] 208 | }, { 209 | "title": "Rebases 'feature' to 'master' and merges it in to master ", 210 | "tip": "git rebase master feature && git checkout master && git merge -" 211 | }, { 212 | "title": "Archive the `master` branch", 213 | "tip": "git archive master --format=zip --output=master.zip" 214 | }, { 215 | "title": "Modify previous commit without modifying the commit message", 216 | "tip": "git add --all && git commit --amend --no-edit" 217 | }, { 218 | "title": "Prunes references to remote branches that have been deleted in the remote.", 219 | "tip": "git fetch -p", 220 | "alternatives": ["git remote prune origin"] 221 | }, { 222 | "title": "Retrieve the commit hash of the initial revision.", 223 | "tip": " git rev-list --reverse HEAD | head -1", 224 | "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"] 225 | }, { 226 | "title": "Visualize the version tree.", 227 | "tip": "git log --pretty=oneline --graph --decorate --all", 228 | "alternatives": ["gitk --all", "git log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d'"] 229 | }, { 230 | "title": "Visualize the tree including commits that are only referenced from reflogs", 231 | "tip": "git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all)" 232 | }, { 233 | "title": "Deploying git tracked subfolder to gh-pages", 234 | "tip": "git subtree push --prefix subfolder_name origin gh-pages", 235 | "alternatives": "git subtree push --prefix subfolder_name origin branch_name" 236 | }, { 237 | "title": "Adding a project to repo using subtree", 238 | "tip": "git subtree add --prefix=/ --squash git@github.com:/.git master" 239 | }, { 240 | "title": "Get latest changes in your repo for a linked project using subtree", 241 | "tip": "git subtree pull --prefix=/ --squash git@github.com:/.git master" 242 | }, { 243 | "title": "Export a branch with history to a file.", 244 | "tip": "git bundle create " 245 | }, { 246 | "title": "Import from a bundle", 247 | "tip": "git clone repo.bundle -b " 248 | }, { 249 | "title": "Get the name of current branch.", 250 | "tip": "git rev-parse --abbrev-ref HEAD" 251 | }, { 252 | "title": "Ignore one file on commit (e.g. Changelog).", 253 | "tip": "git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog" 254 | }, { 255 | "title": "Stash changes before rebasing", 256 | "tip": "git rebase --autostash" 257 | }, { 258 | "title": "Fetch pull request by ID to a local branch", 259 | "tip": "git fetch origin pull//head:", 260 | "alternatives": ["git pull origin pull//head:"] 261 | }, { 262 | "title": "Show the most recent tag on the current branch.", 263 | "tip": "git describe --tags --abbrev=0" 264 | }, { 265 | "title": "Show inline word diff.", 266 | "tip": "git diff --word-diff" 267 | }, { 268 | "title": "Show changes using common diff tools.", 269 | "tip": "git difftool [-t ] " 270 | }, { 271 | "title": "Don’t consider changes for tracked file.", 272 | "tip": "git update-index --assume-unchanged " 273 | }, { 274 | "title": "Undo assume-unchanged.", 275 | "tip": "git update-index --no-assume-unchanged " 276 | }, { 277 | "title": "Clean the files from `.gitignore`.", 278 | "tip": "git clean -X -f" 279 | }, { 280 | "title": "Restore deleted file.", 281 | "tip": "git checkout ^ -- " 282 | }, { 283 | "title": "Restore file to a specific commit-hash", 284 | "tip": "git checkout -- " 285 | }, { 286 | "title": "Always rebase instead of merge on pull.", 287 | "tip": "git config --global pull.rebase true", 288 | "alternatives": ["#git < 1.7.9\ngit config --global branch.autosetuprebase always"] 289 | }, { 290 | "title": "List all the alias and configs.", 291 | "tip": "git config --list" 292 | }, { 293 | "title": "Make git case sensitive.", 294 | "tip": "git config --global core.ignorecase false" 295 | }, { 296 | "title": "Add custom editors.", 297 | "tip": "git config --global core.editor '$EDITOR'" 298 | }, { 299 | "title": "Auto correct typos.", 300 | "tip": "git config --global help.autocorrect 1" 301 | }, { 302 | "title": "Check if the change was a part of a release.", 303 | "tip": "git name-rev --name-only " 304 | }, { 305 | "title": "Dry run. (any command that supports dry-run flag should do.)", 306 | "tip": "git clean -fd --dry-run" 307 | }, { 308 | "title": "Marks your commit as a fix of a previous commit.", 309 | "tip": "git commit --fixup " 310 | }, { 311 | "title": "Squash fixup commits normal commits.", 312 | "tip": "git rebase -i --autosquash" 313 | }, { 314 | "title": "Skip staging area during commit.", 315 | "tip": "git commit --only " 316 | }, { 317 | "title": "Interactive staging.", 318 | "tip": "git add -i" 319 | }, { 320 | "title": "List ignored files.", 321 | "tip": "git check-ignore *" 322 | }, { 323 | "title": "Status of ignored files.", 324 | "tip": "git status --ignored" 325 | }, { 326 | "title": "Commits in Branch1 that are not in Branch2", 327 | "tip": "git log Branch1 ^Branch2" 328 | }, { 329 | "title": "List n last commits", 330 | "tip": "git log -", 331 | "alternatives": ["git log -n "] 332 | }, { 333 | "title": "Reuse recorded resolution, record and reuse previous conflicts resolutions.", 334 | "tip": "git config --global rerere.enabled 1" 335 | }, { 336 | "title": "Open all conflicted files in an editor.", 337 | "tip": "git diff --name-only | uniq | xargs $EDITOR" 338 | }, { 339 | "title": "Count unpacked number of objects and their disk consumption.", 340 | "tip": "git count-objects --human-readable" 341 | }, { 342 | "title": "Prune all unreachable objects from the object database.", 343 | "tip": "git gc --prune=now --aggressive" 344 | }, { 345 | "title": "Instantly browse your working repository in gitweb.", 346 | "tip": "git instaweb [--local] [--httpd=] [--port=] [--browser=]" 347 | }, { 348 | "title": "View the GPG signatures in the commit log", 349 | "tip": "git log --show-signature" 350 | }, { 351 | "title": "Remove entry in the global config.", 352 | "tip": "git config --global --unset " 353 | }, { 354 | "title": "Checkout a new branch without any history", 355 | "tip": "git checkout --orphan " 356 | }, { 357 | "title": "Extract file from another branch.", 358 | "tip": "git show :" 359 | }, { 360 | "title": "List only the root and merge commits.", 361 | "tip": "git log --first-parent" 362 | }, { 363 | "title": "Change previous two commits with an interactive rebase.", 364 | "tip": "git rebase --interactive HEAD~2" 365 | }, { 366 | "title": "List all branch is WIP", 367 | "tip": "git checkout master && git branch --no-merged" 368 | }, { 369 | "title": "Find guilty with binary search", 370 | "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" 371 | }, { 372 | "title": "Bypass pre-commit and commit-msg githooks", 373 | "tip": "git commit --no-verify" 374 | }, { 375 | "title": "List commits and changes to a specific file (even through renaming)", 376 | "tip": "git log --follow -p -- " 377 | }, { 378 | "title": "Clone a single branch", 379 | "tip": "git clone -b --single-branch https://github.com/user/repo.git" 380 | }, { 381 | "title": "Create and switch new branch", 382 | "tip": "git checkout -b ", 383 | "alternatives": ["git branch && git checkout "] 384 | }, { 385 | "title": "Ignore file mode changes on commits", 386 | "tip": "git config core.fileMode false" 387 | }, { 388 | "title": "Turn off git colored terminal output", 389 | "tip": "git config --global color.ui false" 390 | }, { 391 | "title": "Specific color settings", 392 | "tip": "git config --global " 393 | }, { 394 | "title": "Show all local branches ordered by recent commits", 395 | "tip": "git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/" 396 | }, { 397 | "title": "Find lines matching the pattern (regex or string) in tracked files", 398 | "tip": "git grep --heading --line-number 'foo bar'" 399 | }, { 400 | "title": "Clone a shallow copy of a repository", 401 | "tip": "git clone https://github.com/user/repo.git --depth 1" 402 | }, { 403 | "title": "Search Commit log across all branches for given text", 404 | "tip": "git log --all --grep=''" 405 | }, { 406 | "title": "Get first commit in a branch (from master)", 407 | "tip": "git log --oneline master.. | tail -1", 408 | "alternatives": ["git log --reverse master.. | head -6"] 409 | }, { 410 | "title": "Unstaging Staged file", 411 | "tip": "git reset HEAD " 412 | }, { 413 | "title": "Force push to Remote Repository", 414 | "tip": "git push -f " 415 | }, { 416 | "title": "Adding Remote name", 417 | "tip": "git remote add " 418 | }, { 419 | "title": "List all currently configured remotes", 420 | "tip": "git remote -v" 421 | }, { 422 | "title": "Show the author, time and last revision made to each line of a given file", 423 | "tip": "git blame " 424 | }, { 425 | "title": "Group commits by authors and title", 426 | "tip": "git shortlog" 427 | }, { 428 | "title": "Forced push but still ensure you don't overwrite other's work", 429 | "tip": "git push --force-with-lease " 430 | }, { 431 | "title": "Show how many lines does an author contribute", 432 | "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 }' -", 433 | "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"] 434 | }, { 435 | "title": "Revert: Reverting an entire merge", 436 | "tip": "git revert -m 1 " 437 | }, { 438 | "title": "Number of commits in a branch", 439 | "tip": "git rev-list --count " 440 | }, { 441 | "title": "Alias: git undo", 442 | "tip": "git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'" 443 | }, { 444 | "title": "Add object notes", 445 | "tip": "git notes add -m 'Note on the previous commit....'" 446 | }, { 447 | "title": "Show all the git-notes", 448 | "tip": "git log --show-notes='*'" 449 | }, { 450 | "title": "Apply commit from another repository", 451 | "tip": "git --git-dir=/.git format-patch -k -1 --stdout | git am -3 -k" 452 | }, { 453 | "title": "Specific fetch reference", 454 | "tip": "git fetch origin master:refs/remotes/origin/mymaster" 455 | }, { 456 | "title": "Find common ancestor of two branches", 457 | "tip": "git merge-base " 458 | }, { 459 | "title": "List unpushed git commits", 460 | "tip": "git log --branches --not --remotes", 461 | "alternatives": ["git log @{u}..", "git cherry -v"] 462 | }, { 463 | "title": "Add everything, but whitespace changes", 464 | "tip": "git diff --ignore-all-space | git apply --cached" 465 | }, { 466 | "title": "Edit [local/global] git config", 467 | "tip": "git config [--global] --edit" 468 | }, { 469 | "title": "blame on certain range", 470 | "tip": "git blame -L ," 471 | }, { 472 | "title": "Show a Git logical variable.", 473 | "tip": "git var -l | " 474 | }, { 475 | "title": "Preformatted patch file.", 476 | "tip": "git format-patch -M upstream..topic" 477 | }, { 478 | "title": "Get the repo name.", 479 | "tip": "git rev-parse --show-toplevel" 480 | }, { 481 | "title": "logs between date range", 482 | "tip": "git log --since='FEB 1 2017' --until='FEB 14 2017'" 483 | }, { 484 | "title": "Exclude author from logs", 485 | "tip": "git log --perl-regexp --author='^((?!excluded-author-regex).*)$'" 486 | }, { 487 | "title": "Generates a summary of pending changes", 488 | "tip": "git request-pull v1.0 https://git.ko.xz/project master:for-linus" 489 | }, { 490 | "title": "List references in a remote repository", 491 | "tip": "git ls-remote git://git.kernel.org/pub/scm/git/git.git" 492 | }, { 493 | "title": "Backup untracked files.", 494 | "tip": "git ls-files --others -i --exclude-standard | xargs zip untracked.zip" 495 | }, { 496 | "title": "List all git aliases", 497 | "tip": "git config -l | grep alias | sed 's/^alias\\.//g'", 498 | "alternatives": ["git config -l | grep alias | cut -d '.' -f 2"] 499 | }, { 500 | "title": "Show git status short", 501 | "tip": "git status --short --branch" 502 | }, 503 | { 504 | "title": "Checkout a commit prior to a day ago", 505 | "tip": "git checkout master@{yesterday}" 506 | }, { 507 | "title": "Push a new local branch to remote repository and track", 508 | "tip": "git push -u origin " 509 | }, { 510 | "title": "Change a branch base", 511 | "tip": "git rebase --onto " 512 | }, { 513 | "title": "Use SSH instead of HTTPs for remotes", 514 | "tip": "git config --global url.'git@github.com:'.insteadOf 'https://github.com/'" 515 | }, { 516 | "title": "Update a submodule to the latest commit", 517 | "tip": "cd \ngit pull origin \ncd \ngit add \ngit commit -m \"submodule updated\"" 518 | } 519 | ] 520 | --------------------------------------------------------------------------------