├── .doxie.render.js ├── .doxie.render.toc.js ├── .gitignore ├── LICENSE ├── README.md ├── contributing.md ├── 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 | node_modules 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /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 | P.S: All these commands are tested on `git version 2.7.4 (Apple Git-66)`. 5 | 6 | 7 | 8 | * [Everyday Git in twenty commands or so](#everyday-git-in-twenty-commands-or-so) 9 | * [Show helpful guides that come with Git](#show-helpful-guides-that-come-with-git) 10 | * [Overwrite pull](#overwrite-pull) 11 | * [List of all files till a commit](#list-of-all-files-till-a-commit) 12 | * [Git reset first commit](#git-reset-first-commit) 13 | * [List all the conflicted files](#list-all-the-conflicted-files) 14 | * [List of all files changed in a commit](#list-of-all-files-changed-in-a-commit) 15 | * [Unstaged changes since last commit](#unstaged-changes-since-last-commit) 16 | * [Changes staged for commit](#changes-staged-for-commit) 17 | * [Show both staged and unstaged changes](#show-both-staged-and-unstaged-changes) 18 | * [List all branches that are already merged into master](#list-all-branches-that-are-already-merged-into-master) 19 | * [Quickly switch to the previous branch](#quickly-switch-to-the-previous-branch) 20 | * [Remove branches that have already been merged with master](#remove-branches-that-have-already-been-merged-with-master) 21 | * [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) 22 | * [Track upstream branch](#track-upstream-branch) 23 | * [Delete local branch](#delete-local-branch) 24 | * [Delete remote branch](#delete-remote-branch) 25 | * [Undo local changes with the last content in head](#undo-local-changes-with-the-last-content-in-head) 26 | * [Revert: Undo a commit by creating a new commit](#revert-undo-a-commit-by-creating-a-new-commit) 27 | * [Reset: Discard commits, advised for private branch](#reset-discard-commits-advised-for-private-branch) 28 | * [Reword the previous commit message](#reword-the-previous-commit-message) 29 | * [Amend author.](#amend-author) 30 | * [Reset author, after author has been changed in the global config.](#reset-author-after-author-has-been-changed-in-the-global-config) 31 | * [Changing a remote's URL](#changing-a-remotes-url) 32 | * [Get list of all remote references](#get-list-of-all-remote-references) 33 | * [Get list of all local and remote branches](#get-list-of-all-local-and-remote-branches) 34 | * [Get only remote branches](#get-only-remote-branches) 35 | * [Stage parts of a changed file, instead of the entire file](#stage-parts-of-a-changed-file-instead-of-the-entire-file) 36 | * [Get git bash completion](#get-git-bash-completion) 37 | * [What changed since two weeks?](#what-changed-since-two-weeks) 38 | * [See all commits made since forking from master](#see-all-commits-made-since-forking-from-master) 39 | * [Pick commits across branches using cherry-pick](#pick-commits-across-branches-using-cherry-pick) 40 | * [Find out branches containing commit-hash](#find-out-branches-containing-commit-hash) 41 | * [Git Aliases](#git-aliases) 42 | * [Saving current state of tracked files without commiting](#saving-current-state-of-tracked-files-without-commiting) 43 | * [Saving current state including untracked files](#saving-current-state-including-untracked-files) 44 | * [Show list of all saved stashes](#show-list-of-all-saved-stashes) 45 | * [Apply any stash without deleting from the stashed list](#apply-any-stash-without-deleting-from-the-stashed-list) 46 | * [Apply last stashed state and delete it from stashed list](#apply-last-stashed-state-and-delete-it-from-stashed-list) 47 | * [Delete all stored stashes](#delete-all-stored-stashes) 48 | * [Grab a single file from a stash](#grab-a-single-file-from-a-stash) 49 | * [Show all tracked files](#show-all-tracked-files) 50 | * [Show all untracked files](#show-all-untracked-files) 51 | * [Show all ignored files](#show-all-ignored-files) 52 | * [Create new working tree from a repository (git 2.5)](#create-new-working-tree-from-a-repository-git-25) 53 | * [Create new working tree from HEAD state](#create-new-working-tree-from-head-state) 54 | * [Untrack files without deleting](#untrack-files-without-deleting) 55 | * [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) 56 | * [Forcefully remove untracked files](#forcefully-remove-untracked-files) 57 | * [Forcefully remove untracked directory](#forcefully-remove-untracked-directory) 58 | * [Update all the submodules](#update-all-the-submodules) 59 | * [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) 60 | * [Rename a branch](#rename-a-branch) 61 | * [rebases 'feature' to 'master' and merges it in to master ](#rebases-feature-to-master-and-merges-it-in-to-master) 62 | * [Archive the `master` branch](#archive-the-master-branch) 63 | * [Modify previous commit without modifying the commit message](#modify-previous-commit-without-modifying-the-commit-message) 64 | * [Prunes references to remote branches that have been deleted in the remote.](#prunes-references-to-remote-branches-that-have-been-deleted-in-the-remote) 65 | * [Retrieve the commit hash of the initial revision.](#retrieve-the-commit-hash-of-the-initial-revision) 66 | * [Visualize the version tree.](#visualize-the-version-tree) 67 | * [Deploying git tracked subfolder to gh-pages](#deploying-git-tracked-subfolder-to-gh-pages) 68 | * [Adding a project to repo using subtree](#adding-a-project-to-repo-using-subtree) 69 | * [Get latest changes in your repo for a linked project using subtree](#get-latest-changes-in-your-repo-for-a-linked-project-using-subtree) 70 | * [Export a branch with history to a file.](#export-a-branch-with-history-to-a-file) 71 | * [Import from a bundle](#import-from-a-bundle) 72 | * [Get the name of current branch.](#get-the-name-of-current-branch) 73 | * [Ignore one file on commit (e.g. Changelog).](#ignore-one-file-on-commit-eg-changelog) 74 | * [Stash changes before rebasing](#stash-changes-before-rebasing) 75 | * [Fetch pull request by ID to a local branch](#fetch-pull-request-by-id-to-a-local-branch) 76 | * [Show the most recent tag on the current branch.](#show-the-most-recent-tag-on-the-current-branch) 77 | * [Show inline word diff.](#show-inline-word-diff) 78 | * [Don’t consider changes for tracked file.](#dont-consider-changes-for-tracked-file) 79 | * [Undo assume-unchanged.](#undo-assume-unchanged) 80 | * [Clean the files from `.gitignore`.](#clean-the-files-from-gitignore) 81 | * [Restore deleted file.](#restore-deleted-file) 82 | * [Restore file to a specific commit-hash](#restore-file-to-a-specific-commit-hash) 83 | * [Always rebase instead of merge on pull.](#always-rebase-instead-of-merge-on-pull) 84 | * [List all the alias and configs.](#list-all-the-alias-and-configs) 85 | * [Make git case sensitive.](#make-git-case-sensitive) 86 | * [Auto correct typos.](#auto-correct-typos) 87 | * [Check if the change was a part of a release.](#check-if-the-change-was-a-part-of-a-release) 88 | * [Dry run. (any command that supports dry-run flag should do.)](#dry-run-any-command-that-supports-dry-run-flag-should-do) 89 | * [Marks your commit as a fix of a previous commit.](#marks-your-commit-as-a-fix-of-a-previous-commit) 90 | * [squash fixup commits normal commits.](#squash-fixup-commits-normal-commits) 91 | * [skip staging area during commit.](#skip-staging-area-during-commit) 92 | * [List ignored files.](#list-ignored-files) 93 | * [Status of ignored files.](#status-of-ignored-files) 94 | * [Commits in Branch1 that are not in Branch2](#commits-in-branch1-that-are-not-in-branch2) 95 | * [reuse recorded resolution, record and reuse previous conflicts resolutions.](#reuse-recorded-resolution-record-and-reuse-previous-conflicts-resolutions) 96 | * [Open all conflicted files in an editor.](#open-all-conflicted-files-in-an-editor) 97 | * [Count unpacked number of objects and their disk consumption.](#count-unpacked-number-of-objects-and-their-disk-consumption) 98 | * [Prune all unreachable objects from the object database.](#prune-all-unreachable-objects-from-the-object-database) 99 | * [Instantly browse your working repository in gitweb.](#instantly-browse-your-working-repository-in-gitweb) 100 | * [View the GPG signatures in the commit log](#view-the-gpg-signatures-in-the-commit-log) 101 | * [Remove entry in the global config.](#remove-entry-in-the-global-config) 102 | * [Checkout a new branch without any history](#checkout-a-new-branch-without-any-history) 103 | * [File diff between staging and the last file version.](#file-diff-between-staging-and-the-last-file-version) 104 | * [Extract file from another branch.](#extract-file-from-another-branch) 105 | * [List only the root and merge commits.](#list-only-the-root-and-merge-commits) 106 | * [Merge previous two commits into one.](#merge-previous-two-commits-into-one) 107 | * [List all branch is WIP](#list-all-branch-is-wip) 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | ## Everyday Git in twenty commands or so 116 | ```sh 117 | git help everyday 118 | ``` 119 | 120 | ## Show helpful guides that come with Git 121 | ```sh 122 | git help -g 123 | ``` 124 | 125 | ## Overwrite pull 126 | ```sh 127 | git fetch --all && git reset --hard origin/master 128 | ``` 129 | 130 | ## List of all files till a commit 131 | ```sh 132 | git ls-tree --name-only -r 133 | ``` 134 | 135 | ## Git reset first commit 136 | ```sh 137 | git update-ref -d HEAD 138 | ``` 139 | 140 | ## List all the conflicted files 141 | ```sh 142 | git diff --name-only --diff-filter=U 143 | ``` 144 | 145 | ## List of all files changed in a commit 146 | ```sh 147 | git diff-tree --no-commit-id --name-only -r 148 | ``` 149 | 150 | ## Unstaged changes since last commit 151 | ```sh 152 | git diff 153 | ``` 154 | 155 | ## Changes staged for commit 156 | ```sh 157 | git diff --cached 158 | ``` 159 | 160 | ## Show both staged and unstaged changes 161 | ```sh 162 | git diff HEAD 163 | ``` 164 | 165 | ## List all branches that are already merged into master 166 | ```sh 167 | git checkout master && git branch --merged 168 | ``` 169 | 170 | ## Quickly switch to the previous branch 171 | ```sh 172 | git checkout - 173 | ``` 174 | 175 | ## Remove branches that have already been merged with master 176 | ```sh 177 | git branch --merged | grep -v '\*' | xargs -n 1 git branch -d 178 | ``` 179 | 180 | ## List all branches and their upstreams, as well as last commit on branch 181 | ```sh 182 | git branch -vv 183 | ``` 184 | 185 | ## Track upstream branch 186 | ```sh 187 | git branch -u origin/mybranch 188 | ``` 189 | 190 | ## Delete local branch 191 | ```sh 192 | git branch -d 193 | ``` 194 | 195 | ## Delete remote branch 196 | ```sh 197 | git push origin --delete 198 | ``` 199 | 200 | 201 | __Alternatives:__ 202 | ```sh 203 | git push origin : 204 | ``` 205 | 206 | ## Undo local changes with the last content in head 207 | ```sh 208 | git checkout -- 209 | ``` 210 | 211 | ## Revert: Undo a commit by creating a new commit 212 | ```sh 213 | git revert 214 | ``` 215 | 216 | ## Reset: Discard commits, advised for private branch 217 | ```sh 218 | git reset 219 | ``` 220 | 221 | ## Reword the previous commit message 222 | ```sh 223 | git commit -v --amend 224 | ``` 225 | 226 | ## Amend author. 227 | ```sh 228 | git commit --amend --author='Author Name ' 229 | ``` 230 | 231 | ## Reset author, after author has been changed in the global config. 232 | ```sh 233 | git commit --amend --reset-author --no-edit 234 | ``` 235 | 236 | ## Changing a remote's URL 237 | ```sh 238 | git remote set-url origin 239 | ``` 240 | 241 | ## Get list of all remote references 242 | ```sh 243 | git remote 244 | ``` 245 | 246 | 247 | __Alternatives:__ 248 | ```sh 249 | git remote show 250 | ``` 251 | 252 | ## Get list of all local and remote branches 253 | ```sh 254 | git branch -a 255 | ``` 256 | 257 | ## Get only remote branches 258 | ```sh 259 | git branch -r 260 | ``` 261 | 262 | ## Stage parts of a changed file, instead of the entire file 263 | ```sh 264 | git add -p 265 | ``` 266 | 267 | ## Get git bash completion 268 | ```sh 269 | curl http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc 270 | ``` 271 | 272 | ## What changed since two weeks? 273 | ```sh 274 | git whatchanged --since='2 weeks ago' 275 | ``` 276 | 277 | ## See all commits made since forking from master 278 | ```sh 279 | git log --no-merges --stat --reverse master.. 280 | ``` 281 | 282 | ## Pick commits across branches using cherry-pick 283 | ```sh 284 | git checkout && git cherry-pick 285 | ``` 286 | 287 | ## Find out branches containing commit-hash 288 | ```sh 289 | git branch -a --contains 290 | ``` 291 | 292 | 293 | __Alternatives:__ 294 | ```sh 295 | git branch --contains 296 | ``` 297 | 298 | ## Git Aliases 299 | ```sh 300 | git config --global alias. 301 | git config --global alias.st status 302 | ``` 303 | 304 | ## Saving current state of tracked files without commiting 305 | ```sh 306 | git stash 307 | ``` 308 | 309 | 310 | __Alternatives:__ 311 | ```sh 312 | git stash save 313 | ``` 314 | 315 | ## Saving current state including untracked files 316 | ```sh 317 | git stash save -u 318 | ``` 319 | 320 | 321 | __Alternatives:__ 322 | ```sh 323 | git stash save --include-untracked 324 | ``` 325 | 326 | ## Show list of all saved stashes 327 | ```sh 328 | git stash list 329 | ``` 330 | 331 | ## Apply any stash without deleting from the stashed list 332 | ```sh 333 | git stash apply 334 | ``` 335 | 336 | ## Apply last stashed state and delete it from stashed list 337 | ```sh 338 | git stash pop 339 | ``` 340 | 341 | 342 | __Alternatives:__ 343 | ```sh 344 | git stash apply stash@{0} && git stash drop stash@{0} 345 | ``` 346 | 347 | ## Delete all stored stashes 348 | ```sh 349 | git stash clear 350 | ``` 351 | 352 | 353 | __Alternatives:__ 354 | ```sh 355 | git stash drop 356 | ``` 357 | 358 | ## Grab a single file from a stash 359 | ```sh 360 | git checkout -- 361 | ``` 362 | 363 | 364 | __Alternatives:__ 365 | ```sh 366 | git checkout stash@{0} -- 367 | ``` 368 | 369 | ## Show all tracked files 370 | ```sh 371 | git ls-files -t 372 | ``` 373 | 374 | ## Show all untracked files 375 | ```sh 376 | git ls-files --others 377 | ``` 378 | 379 | ## Show all ignored files 380 | ```sh 381 | git ls-files --others -i --exclude-standard 382 | ``` 383 | 384 | ## Create new working tree from a repository (git 2.5) 385 | ```sh 386 | git worktree add -b 387 | ``` 388 | 389 | ## Create new working tree from HEAD state 390 | ```sh 391 | git worktree add --detach HEAD 392 | ``` 393 | 394 | ## Untrack files without deleting 395 | ```sh 396 | git rm --cached 397 | ``` 398 | 399 | 400 | __Alternatives:__ 401 | ```sh 402 | git rm --cached -r 403 | ``` 404 | 405 | ## Before deleting untracked files/directory, do a dry run to get the list of these files/directories 406 | ```sh 407 | git clean -n 408 | ``` 409 | 410 | ## Forcefully remove untracked files 411 | ```sh 412 | git clean -f 413 | ``` 414 | 415 | ## Forcefully remove untracked directory 416 | ```sh 417 | git clean -f -d 418 | ``` 419 | 420 | 421 | __Alternatives:__ 422 | ```sh 423 | git clean -df 424 | ``` 425 | 426 | ## Update all the submodules 427 | ```sh 428 | git submodule foreach git pull 429 | ``` 430 | 431 | ## Show all commits in the current branch yet to be merged to master 432 | ```sh 433 | git cherry -v master 434 | ``` 435 | 436 | 437 | __Alternatives:__ 438 | ```sh 439 | git cherry -v master 440 | ``` 441 | 442 | ## Rename a branch 443 | ```sh 444 | git branch -m 445 | ``` 446 | 447 | 448 | __Alternatives:__ 449 | ```sh 450 | git branch -m [] 451 | ``` 452 | 453 | ## rebases 'feature' to 'master' and merges it in to master 454 | ```sh 455 | git checkout feature && git rebase @{-1} && git checkout @{-2} && git merge @{-1} 456 | ``` 457 | 458 | ## Archive the `master` branch 459 | ```sh 460 | git archive master --format=zip --output=master.zip 461 | ``` 462 | 463 | ## Modify previous commit without modifying the commit message 464 | ```sh 465 | git add --all && git commit --amend --no-edit 466 | ``` 467 | 468 | ## Prunes references to remote branches that have been deleted in the remote. 469 | ```sh 470 | git fetch -p 471 | ``` 472 | 473 | 474 | __Alternatives:__ 475 | ```sh 476 | git remote prune origin 477 | ``` 478 | 479 | ## Retrieve the commit hash of the initial revision. 480 | ```sh 481 | git rev-list --reverse HEAD | head -1 482 | ``` 483 | 484 | ## Visualize the version tree. 485 | ```sh 486 | git log --pretty=oneline --graph --decorate --all 487 | ``` 488 | 489 | 490 | __Alternatives:__ 491 | ```sh 492 | gitk --all 493 | ``` 494 | 495 | ## Deploying git tracked subfolder to gh-pages 496 | ```sh 497 | git subtree push --prefix subfolder_name origin gh-pages 498 | ``` 499 | 500 | ## Adding a project to repo using subtree 501 | ```sh 502 | git subtree add --prefix=/ --squash git@github.com:/.git master 503 | ``` 504 | 505 | ## Get latest changes in your repo for a linked project using subtree 506 | ```sh 507 | git subtree pull --prefix=/ --squash git@github.com:/.git master 508 | ``` 509 | 510 | ## Export a branch with history to a file. 511 | ```sh 512 | git bundle create 513 | ``` 514 | 515 | ## Import from a bundle 516 | ```sh 517 | git clone repo.bundle -b 518 | ``` 519 | 520 | ## Get the name of current branch. 521 | ```sh 522 | git rev-parse --abbrev-ref HEAD 523 | ``` 524 | 525 | ## Ignore one file on commit (e.g. Changelog). 526 | ```sh 527 | git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog 528 | ``` 529 | 530 | ## Stash changes before rebasing 531 | ```sh 532 | git rebase --autostash 533 | ``` 534 | 535 | ## Fetch pull request by ID to a local branch 536 | ```sh 537 | git fetch origin pull//head: 538 | ``` 539 | 540 | 541 | __Alternatives:__ 542 | ```sh 543 | git pull origin pull//head: 544 | ``` 545 | 546 | ## Show the most recent tag on the current branch. 547 | ```sh 548 | git describe --tags --abbrev=0 549 | ``` 550 | 551 | ## Show inline word diff. 552 | ```sh 553 | git diff --word-diff 554 | ``` 555 | 556 | ## Don’t consider changes for tracked file. 557 | ```sh 558 | git update-index --assume-unchanged 559 | ``` 560 | 561 | ## Undo assume-unchanged. 562 | ```sh 563 | git update-index --no-assume-unchanged 564 | ``` 565 | 566 | ## Clean the files from `.gitignore`. 567 | ```sh 568 | git clean -X -f 569 | ``` 570 | 571 | ## Restore deleted file. 572 | ```sh 573 | git checkout ^ -- 574 | ``` 575 | 576 | ## Restore file to a specific commit-hash 577 | ```sh 578 | git checkout -- 579 | ``` 580 | 581 | ## Always rebase instead of merge on pull. 582 | ```sh 583 | git config --global branch.autosetuprebase always 584 | ``` 585 | 586 | ## List all the alias and configs. 587 | ```sh 588 | git config --list 589 | ``` 590 | 591 | ## Make git case sensitive. 592 | ```sh 593 | git config --global core.ignorecase false 594 | ``` 595 | 596 | ## Auto correct typos. 597 | ```sh 598 | git config --global help.autocorrect 1 599 | ``` 600 | 601 | ## Check if the change was a part of a release. 602 | ```sh 603 | git name-rev --name-only 604 | ``` 605 | 606 | ## Dry run. (any command that supports dry-run flag should do.) 607 | ```sh 608 | git clean -fd --dry-run 609 | ``` 610 | 611 | ## Marks your commit as a fix of a previous commit. 612 | ```sh 613 | git commit --fixup 614 | ``` 615 | 616 | ## squash fixup commits normal commits. 617 | ```sh 618 | git rebase -i --autosquash 619 | ``` 620 | 621 | ## skip staging area during commit. 622 | ```sh 623 | git commit -am 624 | ``` 625 | 626 | ## List ignored files. 627 | ```sh 628 | git check-ignore * 629 | ``` 630 | 631 | ## Status of ignored files. 632 | ```sh 633 | git status --ignored 634 | ``` 635 | 636 | ## Commits in Branch1 that are not in Branch2 637 | ```sh 638 | git log Branch1 ^Branch2 639 | ``` 640 | 641 | ## reuse recorded resolution, record and reuse previous conflicts resolutions. 642 | ```sh 643 | git config --global rerere.enabled 1 644 | ``` 645 | 646 | ## Open all conflicted files in an editor. 647 | ```sh 648 | git diff --name-only | uniq | xargs $EDITOR 649 | ``` 650 | 651 | ## Count unpacked number of objects and their disk consumption. 652 | ```sh 653 | git count-objects --human-readable 654 | ``` 655 | 656 | ## Prune all unreachable objects from the object database. 657 | ```sh 658 | git gc --prune=now --aggressive 659 | ``` 660 | 661 | ## Instantly browse your working repository in gitweb. 662 | ```sh 663 | git instaweb [--local] [--httpd=] [--port=] [--browser=] 664 | ``` 665 | 666 | ## View the GPG signatures in the commit log 667 | ```sh 668 | git log --show-signature 669 | ``` 670 | 671 | ## Remove entry in the global config. 672 | ```sh 673 | git config --global --unset 674 | ``` 675 | 676 | ## Checkout a new branch without any history 677 | ```sh 678 | git checkout --orphan 679 | ``` 680 | 681 | ## File diff between staging and the last file version. 682 | ```sh 683 | git diff --staged 684 | ``` 685 | 686 | ## Extract file from another branch. 687 | ```sh 688 | git show : 689 | ``` 690 | 691 | ## List only the root and merge commits. 692 | ```sh 693 | git log --first-parent 694 | ``` 695 | 696 | ## Merge previous two commits into one. 697 | ```sh 698 | git rebase --interactive HEAD~2 699 | ``` 700 | 701 | ## List all branch is WIP 702 | ```sh 703 | git checkout master && git branch --no-merged 704 | ``` 705 | 706 | 707 | 708 | -------------------------------------------------------------------------------- /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 | * Edit [tips.json](./tips.json) to add your tip in the below format: 11 | 12 | ```js 13 | { 14 | "title": , 15 | "tip": , 16 | "alternatives": [Optional list of alternatives] 17 | } 18 | ``` 19 | 20 | * Commit, push and send a PR! 21 | -------------------------------------------------------------------------------- /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": "Overwrite pull", 9 | "tip": "git fetch --all && git reset --hard origin/master" 10 | }, { 11 | "title": "List of all files till a commit", 12 | "tip": "git ls-tree --name-only -r " 13 | }, { 14 | "title": "Git reset first commit", 15 | "tip": "git update-ref -d HEAD" 16 | }, { 17 | "title": "List all the conflicted files", 18 | "tip": "git diff --name-only --diff-filter=U" 19 | }, { 20 | "title": "List of all files changed in a commit", 21 | "tip": "git diff-tree --no-commit-id --name-only -r " 22 | }, { 23 | "title": "Unstaged changes since last commit", 24 | "tip": "git diff" 25 | }, { 26 | "title": "Changes staged for commit", 27 | "tip": "git diff --cached" 28 | }, { 29 | "title": "Show both staged and unstaged changes", 30 | "tip": "git diff HEAD" 31 | }, { 32 | "title": "List all branches that are already merged into master", 33 | "tip": "git checkout master && git branch --merged" 34 | }, { 35 | "title": "Quickly switch to the previous branch", 36 | "tip": "git checkout -" 37 | }, { 38 | "title": "Remove branches that have already been merged with master", 39 | "tip": "git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d" 40 | }, { 41 | "title": "List all branches and their upstreams, as well as last commit on branch", 42 | "tip": "git branch -vv" 43 | }, { 44 | "title": "Track upstream branch", 45 | "tip": "git branch -u origin/mybranch" 46 | }, { 47 | "title": "Delete local branch", 48 | "tip": "git branch -d " 49 | }, { 50 | "title": "Delete remote branch", 51 | "tip": "git push origin --delete ", 52 | "alternatives": ["git push origin :"] 53 | }, { 54 | "title": "Undo local changes with the last content in head", 55 | "tip": "git checkout -- " 56 | }, { 57 | "title": "Revert: Undo a commit by creating a new commit", 58 | "tip": "git revert " 59 | }, { 60 | "title": "Reset: Discard commits, advised for private branch", 61 | "tip": "git reset " 62 | }, { 63 | "title": "Reword the previous commit message", 64 | "tip": "git commit -v --amend" 65 | }, { 66 | "title": "Amend author.", 67 | "tip": "git commit --amend --author='Author Name '" 68 | }, { 69 | "title": "Reset author, after author has been changed in the global config.", 70 | "tip": "git commit --amend --reset-author --no-edit" 71 | }, { 72 | "title": "Changing a remote's URL", 73 | "tip": "git remote set-url origin " 74 | }, { 75 | "title": "Get list of all remote references", 76 | "tip": "git remote", 77 | "alternatives": ["git remote show"] 78 | }, { 79 | "title": "Get list of all local and remote branches", 80 | "tip": "git branch -a" 81 | }, { 82 | "title": "Get only remote branches", 83 | "tip": "git branch -r" 84 | }, { 85 | "title": "Stage parts of a changed file, instead of the entire file", 86 | "tip": "git add -p" 87 | }, { 88 | "title": "Get git bash completion", 89 | "tip": "curl http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc" 90 | }, { 91 | "title": "What changed since two weeks?", 92 | "tip": "git whatchanged --since='2 weeks ago'" 93 | }, { 94 | "title": "See all commits made since forking from master", 95 | "tip": "git log --no-merges --stat --reverse master.." 96 | }, { 97 | "title": "Pick commits across branches using cherry-pick", 98 | "tip": "git checkout && git cherry-pick " 99 | }, { 100 | "title": "Find out branches containing commit-hash", 101 | "tip": "git branch -a --contains ", 102 | "alternatives": ["git branch --contains "] 103 | }, { 104 | "title": "Git Aliases", 105 | "tip": "git config --global alias. \ngit config --global alias.st status" 106 | }, { 107 | "title": "Saving current state of tracked files without commiting", 108 | "tip": "git stash", 109 | "alternatives": ["git stash save"] 110 | }, { 111 | "title": "Saving current state including untracked files", 112 | "tip": "git stash save -u", 113 | "alternatives": ["git stash save --include-untracked"] 114 | }, { 115 | "title": "Show list of all saved stashes", 116 | "tip": "git stash list" 117 | }, { 118 | "title": "Apply any stash without deleting from the stashed list", 119 | "tip": "git stash apply " 120 | }, { 121 | "title": "Apply last stashed state and delete it from stashed list", 122 | "tip": "git stash pop", 123 | "alternatives": ["git stash apply stash@{0} && git stash drop stash@{0}"] 124 | }, { 125 | "title": "Delete all stored stashes", 126 | "tip": "git stash clear", 127 | "alternatives": ["git stash drop "] 128 | }, { 129 | "title": "Grab a single file from a stash", 130 | "tip": "git checkout -- ", 131 | "alternatives": ["git checkout stash@{0} -- "] 132 | }, { 133 | "title": "Show all tracked files", 134 | "tip": "git ls-files -t" 135 | }, { 136 | "title": "Show all untracked files", 137 | "tip": "git ls-files --others" 138 | }, { 139 | "title": "Show all ignored files", 140 | "tip": "git ls-files --others -i --exclude-standard" 141 | }, { 142 | "title": "Create new working tree from a repository (git 2.5)", 143 | "tip": "git worktree add -b " 144 | }, { 145 | "title": "Create new working tree from HEAD state", 146 | "tip": "git worktree add --detach HEAD" 147 | }, { 148 | "title": "Untrack files without deleting", 149 | "tip": "git rm --cached ", 150 | "alternatives": ["git rm --cached -r "] 151 | }, { 152 | "title": "Before deleting untracked files/directory, do a dry run to get the list of these files/directories", 153 | "tip": "git clean -n" 154 | }, { 155 | "title": "Forcefully remove untracked files", 156 | "tip": "git clean -f" 157 | }, { 158 | "title": "Forcefully remove untracked directory", 159 | "tip": "git clean -f -d", 160 | "alternatives": ["git clean -df"] 161 | }, { 162 | "title": "Update all the submodules", 163 | "tip": "git submodule foreach git pull" 164 | }, { 165 | "title": "Show all commits in the current branch yet to be merged to master", 166 | "tip": "git cherry -v master", 167 | "alternatives": ["git cherry -v master "] 168 | }, { 169 | "title": "Rename a branch", 170 | "tip": "git branch -m ", 171 | "alternatives": ["git branch -m [] "] 172 | }, { 173 | "title": "rebases 'feature' to 'master' and merges it in to master ", 174 | "tip": "git checkout feature && git rebase @{-1} && git checkout @{-2} && git merge @{-1}" 175 | }, { 176 | "title": "Archive the `master` branch", 177 | "tip": "git archive master --format=zip --output=master.zip" 178 | }, { 179 | "title": "Modify previous commit without modifying the commit message", 180 | "tip": "git add --all && git commit --amend --no-edit" 181 | }, { 182 | "title": "Prunes references to remote branches that have been deleted in the remote.", 183 | "tip": "git fetch -p", 184 | "alternatives": ["git remote prune origin"] 185 | }, { 186 | "title": "Retrieve the commit hash of the initial revision.", 187 | "tip": " git rev-list --reverse HEAD | head -1" 188 | }, { 189 | "title": "Visualize the version tree.", 190 | "tip": "git log --pretty=oneline --graph --decorate --all", 191 | "alternatives": ["gitk --all"] 192 | }, { 193 | "title": "Deploying git tracked subfolder to gh-pages", 194 | "tip": "git subtree push --prefix subfolder_name origin gh-pages", 195 | "alternatives": "git subtree push --prefix subfolder_name origin branch_name" 196 | }, { 197 | "title": "Adding a project to repo using subtree", 198 | "tip": "git subtree add --prefix=/ --squash git@github.com:/.git master" 199 | }, { 200 | "title": "Get latest changes in your repo for a linked project using subtree", 201 | "tip": "git subtree pull --prefix=/ --squash git@github.com:/.git master" 202 | }, { 203 | "title": "Export a branch with history to a file.", 204 | "tip": "git bundle create " 205 | }, { 206 | "title": "Import from a bundle", 207 | "tip": "git clone repo.bundle -b " 208 | }, { 209 | "title": "Get the name of current branch.", 210 | "tip": "git rev-parse --abbrev-ref HEAD" 211 | }, { 212 | "title": "Ignore one file on commit (e.g. Changelog).", 213 | "tip": "git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog" 214 | }, { 215 | "title": "Stash changes before rebasing", 216 | "tip": "git rebase --autostash" 217 | }, { 218 | "title": "Fetch pull request by ID to a local branch", 219 | "tip": "git fetch origin pull//head:", 220 | "alternatives": ["git pull origin pull//head:"] 221 | }, { 222 | "title": "Show the most recent tag on the current branch.", 223 | "tip": "git describe --tags --abbrev=0" 224 | }, { 225 | "title": "Show inline word diff.", 226 | "tip": "git diff --word-diff" 227 | }, { 228 | "title": "Don’t consider changes for tracked file.", 229 | "tip": "git update-index --assume-unchanged " 230 | }, { 231 | "title": "Undo assume-unchanged.", 232 | "tip": "git update-index --no-assume-unchanged " 233 | }, { 234 | "title": "Clean the files from `.gitignore`.", 235 | "tip": "git clean -X -f" 236 | }, { 237 | "title": "Restore deleted file.", 238 | "tip": "git checkout ^ -- " 239 | }, { 240 | "title": "Restore file to a specific commit-hash", 241 | "tip": "git checkout -- " 242 | }, { 243 | "title": "Always rebase instead of merge on pull.", 244 | "tip": "git config --global branch.autosetuprebase always" 245 | }, { 246 | "title": "List all the alias and configs.", 247 | "tip": "git config --list" 248 | }, { 249 | "title": "Make git case sensitive.", 250 | "tip": "git config --global core.ignorecase false" 251 | }, { 252 | "title": "Auto correct typos.", 253 | "tip": "git config --global help.autocorrect 1" 254 | }, { 255 | "title": "Check if the change was a part of a release.", 256 | "tip": "git name-rev --name-only " 257 | }, { 258 | "title": "Dry run. (any command that supports dry-run flag should do.)", 259 | "tip": "git clean -fd --dry-run" 260 | }, { 261 | "title": "Marks your commit as a fix of a previous commit.", 262 | "tip": "git commit --fixup " 263 | }, { 264 | "title": "squash fixup commits normal commits.", 265 | "tip": "git rebase -i --autosquash" 266 | }, { 267 | "title": "skip staging area during commit.", 268 | "tip": "git commit -am " 269 | }, { 270 | "title": "List ignored files.", 271 | "tip": "git check-ignore *" 272 | }, { 273 | "title": "Status of ignored files.", 274 | "tip": "git status --ignored" 275 | }, { 276 | "title": "Commits in Branch1 that are not in Branch2", 277 | "tip": "git log Branch1 ^Branch2" 278 | }, { 279 | "title": "reuse recorded resolution, record and reuse previous conflicts resolutions.", 280 | "tip":"git config --global rerere.enabled 1" 281 | }, { 282 | "title": "Open all conflicted files in an editor.", 283 | "tip": "git diff --name-only | uniq | xargs $EDITOR" 284 | }, { 285 | "title": "Count unpacked number of objects and their disk consumption.", 286 | "tip": "git count-objects --human-readable" 287 | }, { 288 | "title": "Prune all unreachable objects from the object database.", 289 | "tip": "git gc --prune=now --aggressive" 290 | },{ 291 | "title": "Instantly browse your working repository in gitweb.", 292 | "tip": "git instaweb [--local] [--httpd=] [--port=] [--browser=]" 293 | },{ 294 | "title": "View the GPG signatures in the commit log", 295 | "tip": "git log --show-signature" 296 | }, { 297 | "title": "Remove entry in the global config.", 298 | "tip": "git config --global --unset " 299 | },{ 300 | "title": "Checkout a new branch without any history", 301 | "tip": "git checkout --orphan " 302 | },{ 303 | "title": "File diff between staging and the last file version.", 304 | "tip": "git diff --staged" 305 | },{ 306 | "title": "Extract file from another branch.", 307 | "tip": "git show :" 308 | }, { 309 | "title": "List only the root and merge commits.", 310 | "tip": "git log --first-parent" 311 | }, { 312 | "title": "Merge previous two commits into one.", 313 | "tip": "git rebase --interactive HEAD~2" 314 | }, { 315 | "title": "List all branch is WIP", 316 | "tip": "git checkout master && git branch --no-merged" 317 | }] 318 | --------------------------------------------------------------------------------