-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathtips.json
More file actions
986 lines (986 loc) · 32.5 KB
/
tips.json
File metadata and controls
986 lines (986 loc) · 32.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
[
{
"title": "Everyday Git in twenty commands or so",
"tip": "git help everyday",
"category": "Miscellaneous"
},
{
"title": "Show helpful guides that come with Git",
"tip": "git help -g",
"category": "Log and History"
},
{
"title": "Search change by content",
"tip": "git log -S'<a term in the source>'",
"category": "Log and History"
},
{
"title": "Show changes over time for specific file",
"tip": "git log -p <file_name>",
"category": "Log and History"
},
{
"title": "Remove sensitive data from history, after a push",
"tip": "git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch <path-to-your-file>' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all",
"category": "Setup and Config"
},
{
"title": "Sync with remote, overwrite local changes",
"tip": "git fetch origin && git reset --hard origin/master && git clean -f -d",
"category": "Undoing Changes"
},
{
"title": "List of all files till a commit",
"tip": "git ls-tree --name-only -r <commit-ish>",
"category": "Basic Operations"
},
{
"title": "Git reset first commit",
"tip": "git update-ref -d HEAD",
"category": "Undoing Changes"
},
{
"title": "Reset: preserve uncommitted local changes",
"tip": "git reset --keep <commit>",
"category": "Undoing Changes"
},
{
"title": "List all the conflicted files",
"tip": "git diff --name-only --diff-filter=U",
"category": "Log and History"
},
{
"title": "List of all files changed in a commit",
"tip": "git diff-tree --no-commit-id --name-only -r <commit-ish>",
"category": "Log and History"
},
{
"title": "Unstaged changes since last commit",
"tip": "git diff",
"category": "Log and History"
},
{
"title": "Changes staged for commit",
"tip": "git diff --cached",
"alternatives": [
"git diff --staged"
],
"category": "Log and History"
},
{
"title": "Show both staged and unstaged changes",
"tip": "git diff HEAD",
"category": "Log and History"
},
{
"title": "List all branches that are already merged into master",
"tip": "git branch --merged master",
"category": "Branching"
},
{
"title": "Quickly switch to the previous branch",
"tip": "git checkout -",
"alternatives": [
"git checkout @{-1}"
],
"category": "Basic Operations"
},
{
"title": "Remove branches that have already been merged with master",
"tip": "git branch --merged master | grep -v '^\\*' | xargs -n 1 git branch -d",
"alternatives": [
"git branch --merged master | grep -v '^\\*\\| master' | xargs -n 1 git branch -d # will not delete master if master is not checked out"
],
"category": "Branching"
},
{
"title": "List all branches and their upstreams, as well as last commit on branch",
"tip": "git branch -vv",
"category": "Branching"
},
{
"title": "Track upstream branch",
"tip": "git branch -u origin/mybranch",
"category": "Branching"
},
{
"title": "Delete local branch",
"tip": "git branch -d <local_branchname>",
"category": "Branching"
},
{
"title": "Delete remote branch",
"tip": "git push origin --delete <remote_branchname>",
"alternatives": [
"git push origin :<remote_branchname>",
"git branch -dr <remote/branch>"
],
"category": "Basic Operations"
},
{
"title": "Create local tag",
"tip": "git tag <tag-name>",
"category": "Tagging"
},
{
"title": "Delete local tag",
"tip": "git tag -d <tag-name>",
"category": "Tagging"
},
{
"title": "Delete remote tag",
"tip": "git push origin :refs/tags/<tag-name>",
"category": "Basic Operations"
},
{
"title": "Undo local changes with the content in index(staging)",
"tip": "git checkout -- <file_name>",
"category": "Basic Operations"
},
{
"title": "Revert: Undo a commit by creating a new commit",
"tip": "git revert <commit-ish>",
"category": "Undoing Changes"
},
{
"title": "Reset: Discard commits, advised for private branch",
"tip": "git reset <commit-ish>",
"category": "Undoing Changes"
},
{
"title": "Reword the previous commit message",
"tip": "git commit -v --amend",
"category": "Basic Operations"
},
{
"title": "See commit history for just the current branch",
"tip": "git cherry -v master",
"category": "Basic Operations"
},
{
"title": "Amend author.",
"tip": "git commit --amend --author='Author Name <email@address.com>'",
"category": "Basic Operations"
},
{
"title": "Reset author, after author has been changed in the global config.",
"tip": "git commit --amend --reset-author --no-edit",
"category": "Setup and Config"
},
{
"title": "Changing a remote's URL",
"tip": "git remote set-url origin <URL>",
"category": "Remotes"
},
{
"title": "Get list of all remote references",
"tip": "git remote",
"alternatives": [
"git remote show"
],
"category": "Remotes"
},
{
"title": "Get list of all local and remote branches",
"tip": "git branch -a",
"category": "Branching"
},
{
"title": "Get only remote branches",
"tip": "git branch -r",
"category": "Branching"
},
{
"title": "Stage parts of a changed file, instead of the entire file",
"tip": "git add -p",
"category": "Basic Operations"
},
{
"title": "Get git bash completion",
"tip": "curl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc",
"category": "Setup and Config"
},
{
"title": "What changed since two weeks?",
"tip": "git log --no-merges --raw --since='2 weeks ago'",
"alternatives": [
"git whatchanged --since='2 weeks ago'"
],
"category": "Log and History"
},
{
"title": "See all commits made since forking from master",
"tip": "git log --no-merges --stat --reverse master..",
"category": "Log and History"
},
{
"title": "Pick commits across branches using cherry-pick",
"tip": "git checkout <branch-name> && git cherry-pick <commit-ish>",
"category": "Basic Operations"
},
{
"title": "Find out branches containing commit-hash",
"tip": "git branch -a --contains <commit-ish>",
"alternatives": [
"git branch --contains <commit-ish>"
],
"category": "Branching"
},
{
"title": "Git Aliases",
"tip": "git config --global alias.<handle> <command> \ngit config --global alias.st status",
"category": "Setup and Config"
},
{
"title": "Saving current state of tracked files without committing",
"tip": "git stash",
"alternatives": [
"git stash push"
],
"category": "Stashing"
},
{
"title": "Saving current state of unstaged changes to tracked files",
"tip": "git stash -k",
"alternatives": [
"git stash --keep-index",
"git stash push --keep-index"
],
"category": "Stashing"
},
{
"title": "Saving current state including untracked files",
"tip": "git stash -u",
"alternatives": [
"git stash push -u",
"git stash push --include-untracked"
],
"category": "Stashing"
},
{
"title": "Saving current state with message",
"tip": "git stash push -m <message>",
"alternatives": [
"git stash push --message <message>"
],
"category": "Stashing"
},
{
"title": "Saving current state of all files (ignored, untracked, and tracked)",
"tip": "git stash -a",
"alternatives": [
"git stash --all",
"git stash push --all"
],
"category": "Stashing"
},
{
"title": "Show list of all saved stashes",
"tip": "git stash list",
"category": "Stashing"
},
{
"title": "Show the contents of any stash in patch form",
"tip": "git stash show -p <stash@{n}>",
"category": "Stashing"
},
{
"title": "Apply any stash without deleting from the stashed list",
"tip": "git stash apply <stash@{n}>",
"category": "Stashing"
},
{
"title": "Apply last stashed state and delete it from stashed list",
"tip": "git stash pop",
"alternatives": [
"git stash apply stash@{0} && git stash drop stash@{0}"
],
"category": "Stashing"
},
{
"title": "Delete all stored stashes",
"tip": "git stash clear",
"alternatives": [
"git stash drop <stash@{n}>"
],
"category": "Stashing"
},
{
"title": "Grab a single file from a stash",
"tip": "git checkout <stash@{n}> -- <file_path>",
"alternatives": [
"git checkout stash@{0} -- <file_path>"
],
"category": "Basic Operations"
},
{
"title": "Show all tracked files",
"tip": "git ls-files -t",
"category": "Log and History"
},
{
"title": "Show all untracked files",
"tip": "git ls-files --others",
"category": "Log and History"
},
{
"title": "Show all ignored files",
"tip": "git ls-files --others -i --exclude-standard",
"category": "Log and History"
},
{
"title": "Create new working tree from a repository (git 2.5)",
"tip": "git worktree add -b <branch-name> <path> <start-point>",
"category": "Basic Operations"
},
{
"title": "Create new working tree from HEAD state",
"tip": "git worktree add --detach <path> HEAD",
"category": "Basic Operations"
},
{
"title": "Untrack files without deleting",
"tip": "git rm --cached <file_path>",
"alternatives": [
"git rm --cached -r <directory_path>"
],
"category": "Miscellaneous"
},
{
"title": "Before deleting untracked files/directory, do a dry run to get the list of these files/directories",
"tip": "git clean -n",
"category": "Undoing Changes"
},
{
"title": "Forcefully remove untracked files",
"tip": "git clean -f",
"category": "Undoing Changes"
},
{
"title": "Forcefully remove untracked directory",
"tip": "git clean -f -d",
"category": "Undoing Changes"
},
{
"title": "Update all the submodules",
"tip": "git submodule foreach git pull",
"alternatives": [
"git submodule update --init --recursive",
"git submodule update --remote"
],
"category": "Submodules and Subtrees"
},
{
"title": "Show all commits in the current branch yet to be merged to master",
"tip": "git cherry -v master",
"alternatives": [
"git cherry -v master <branch-to-be-merged>"
],
"category": "Basic Operations"
},
{
"title": "Rename a branch",
"tip": "git branch -m <new-branch-name>",
"alternatives": [
"git branch -m [<old-branch-name>] <new-branch-name>"
],
"category": "Branching"
},
{
"title": "Rebases 'feature' to 'master' and merges it in to master ",
"tip": "git rebase master feature && git checkout master && git merge -",
"category": "Merging and Rebasing"
},
{
"title": "Archive the `master` branch",
"tip": "git archive master --format=zip --output=master.zip",
"category": "Branching"
},
{
"title": "Modify previous commit without modifying the commit message",
"tip": "git add --all && git commit --amend --no-edit",
"category": "Basic Operations"
},
{
"title": "Prunes references to remove branches that have been deleted in the remote.",
"tip": "git fetch -p",
"alternatives": [
"git remote prune origin"
],
"category": "Basic Operations"
},
{
"title": "Delete local branches that has been squash and merged in the remote.",
"tip": "git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D",
"category": "Branching"
},
{
"title": "Retrieve the commit hash of the initial revision.",
"tip": " git rev-list --reverse HEAD | head -1",
"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"
],
"category": "Basic Operations"
},
{
"title": "Visualize the version tree.",
"tip": "git log --pretty=oneline --graph --decorate --all",
"alternatives": [
"gitk --all",
"git log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d'"
],
"category": "Log and History"
},
{
"title": "Visualize the tree including commits that are only referenced from reflogs",
"tip": "git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all)",
"category": "Log and History"
},
{
"title": "Deploying git tracked subfolder to gh-pages",
"tip": "git subtree push --prefix subfolder_name origin gh-pages",
"alternatives": [
"git subtree push --prefix subfolder_name origin branch_name"
],
"category": "Submodules and Subtrees"
},
{
"title": "Adding a project to repo using subtree",
"tip": "git subtree add --prefix=<directory_name>/<project_name> --squash git@github.com:<username>/<project_name>.git master",
"category": "Submodules and Subtrees"
},
{
"title": "Get latest changes in your repo for a linked project using subtree",
"tip": "git subtree pull --prefix=<directory_name>/<project_name> --squash git@github.com:<username>/<project_name>.git master",
"category": "Submodules and Subtrees"
},
{
"title": "Export a branch with history to a file.",
"tip": "git bundle create <file> <branch-name>",
"category": "Branching"
},
{
"title": "Import from a bundle",
"tip": "git clone repo.bundle <repo-dir> -b <branch-name>",
"category": "Basic Operations"
},
{
"title": "Get the name of current branch.",
"tip": "git rev-parse --abbrev-ref HEAD",
"category": "Branching"
},
{
"title": "Ignore one file on commit (e.g. Changelog).",
"tip": "git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog",
"category": "Basic Operations"
},
{
"title": "Stash changes before rebasing",
"tip": "git rebase --autostash",
"category": "Merging and Rebasing"
},
{
"title": "Fetch pull request by ID to a local branch",
"tip": "git fetch origin pull/<id>/head:<branch-name>",
"alternatives": [
"git pull origin pull/<id>/head:<branch-name>"
],
"category": "Basic Operations"
},
{
"title": "Show the most recent tag on the current branch.",
"tip": "git describe --tags --abbrev=0",
"category": "Branching"
},
{
"title": "Show inline word diff.",
"tip": "git diff --word-diff",
"category": "Log and History"
},
{
"title": "Show changes using common diff tools.",
"tip": "git difftool [-t <tool>] <commit1> <commit2> <path>",
"category": "Log and History"
},
{
"title": "Don\u2019t consider changes for tracked file.",
"tip": "git update-index --assume-unchanged <file_name>",
"category": "Miscellaneous"
},
{
"title": "Undo assume-unchanged.",
"tip": "git update-index --no-assume-unchanged <file_name>",
"category": "Undoing Changes"
},
{
"title": "Clean the files from `.gitignore`.",
"tip": "git clean -X -f",
"category": "Undoing Changes"
},
{
"title": "Restore deleted file.",
"tip": "git checkout <deleting_commit> -- <file_path>",
"category": "Basic Operations"
},
{
"title": "Restore file to a specific commit-hash",
"tip": "git checkout <commit-ish> -- <file_path>",
"category": "Basic Operations"
},
{
"title": "Always rebase instead of merge on pull.",
"tip": "git config --global pull.rebase true",
"alternatives": [
"#git < 1.7.9\ngit config --global branch.autosetuprebase always"
],
"category": "Setup and Config"
},
{
"title": "List all the alias and configs.",
"tip": "git config --list",
"category": "Setup and Config"
},
{
"title": "Make git case sensitive.",
"tip": "git config --global core.ignorecase false",
"category": "Setup and Config"
},
{
"title": "Add custom editors.",
"tip": "git config --global core.editor '$EDITOR'",
"category": "Setup and Config"
},
{
"title": "Auto correct typos.",
"tip": "git config --global help.autocorrect 1",
"category": "Setup and Config"
},
{
"title": "Check if the change was a part of a release.",
"tip": "git name-rev --name-only <SHA-1>",
"category": "Miscellaneous"
},
{
"title": "Dry run. (any command that supports dry-run flag should do.)",
"tip": "git clean -fd --dry-run",
"category": "Undoing Changes"
},
{
"title": "Marks your commit as a fix of a previous commit.",
"tip": "git commit --fixup <SHA-1>",
"category": "Basic Operations"
},
{
"title": "Squash fixup commits normal commits.",
"tip": "git rebase -i --autosquash",
"category": "Merging and Rebasing"
},
{
"title": "Skip staging area during commit.",
"tip": "git commit --only <file_path>",
"category": "Basic Operations"
},
{
"title": "Interactive staging.",
"tip": "git add -i",
"category": "Basic Operations"
},
{
"title": "List ignored files.",
"tip": "git check-ignore *",
"category": "Miscellaneous"
},
{
"title": "Status of ignored files.",
"tip": "git status --ignored",
"category": "Basic Operations"
},
{
"title": "Commits in Branch1 that are not in Branch2",
"tip": "git log Branch1 ^Branch2",
"category": "Log and History"
},
{
"title": "List n last commits",
"tip": "git log -<n>",
"alternatives": [
"git log -n <n>"
],
"category": "Log and History"
},
{
"title": "Reuse recorded resolution, record and reuse previous conflicts resolutions.",
"tip": "git config --global rerere.enabled 1",
"category": "Setup and Config"
},
{
"title": "Open all conflicted files in an editor.",
"tip": "git diff --name-only | uniq | xargs $EDITOR",
"category": "Log and History"
},
{
"title": "Count unpacked number of objects and their disk consumption.",
"tip": "git count-objects --human-readable",
"category": "Miscellaneous"
},
{
"title": "Prune all unreachable objects from the object database.",
"tip": "git gc --prune=now --aggressive",
"category": "Miscellaneous"
},
{
"title": "Instantly browse your working repository in gitweb.",
"tip": "git instaweb [--local] [--httpd=<httpd>] [--port=<port>] [--browser=<browser>]",
"category": "Miscellaneous"
},
{
"title": "View the GPG signatures in the commit log",
"tip": "git log --show-signature",
"category": "Log and History"
},
{
"title": "Remove entry in the global config.",
"tip": "git config --global --unset <entry-name>",
"category": "Setup and Config"
},
{
"title": "Checkout a new branch without any history",
"tip": "git checkout --orphan <branch_name>",
"category": "Basic Operations"
},
{
"title": "Extract file from another branch.",
"tip": "git show <branch_name>:<file_name>",
"category": "Log and History"
},
{
"title": "List only the root and merge commits.",
"tip": "git log --first-parent",
"category": "Log and History"
},
{
"title": "Change previous two commits with an interactive rebase.",
"tip": "git rebase --interactive HEAD~2",
"category": "Merging and Rebasing"
},
{
"title": "List all branch is WIP",
"tip": "git checkout master && git branch --no-merged",
"category": "Branching"
},
{
"title": "Find guilty with binary search",
"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",
"category": "Basic Operations"
},
{
"title": "Bypass pre-commit and commit-msg githooks",
"tip": "git commit --no-verify",
"category": "Basic Operations"
},
{
"title": "List commits and changes to a specific file (even through renaming)",
"tip": "git log --follow -p -- <file_path>",
"category": "Log and History"
},
{
"title": "Clone a single branch",
"tip": "git clone -b <branch-name> --single-branch https://github.com/user/repo.git",
"category": "Basic Operations"
},
{
"title": "Create and switch new branch",
"tip": "git checkout -b <branch-name>",
"alternatives": [
"git branch <branch-name> && git checkout <branch-name>",
"git switch -c <branch-name>"
],
"category": "Basic Operations"
},
{
"title": "Ignore file mode changes on commits",
"tip": "git config core.fileMode false",
"category": "Setup and Config"
},
{
"title": "Turn off git colored terminal output",
"tip": "git config --global color.ui false",
"category": "Setup and Config"
},
{
"title": "Specific color settings",
"tip": "git config --global <specific command e.g branch, diff> <true, false or always>",
"category": "Setup and Config"
},
{
"title": "Show all local branches ordered by recent commits",
"tip": "git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/",
"category": "Basic Operations"
},
{
"title": "Find lines matching the pattern (regex or string) in tracked files",
"tip": "git grep --heading --line-number 'foo bar'",
"category": "Miscellaneous"
},
{
"title": "Clone a shallow copy of a repository",
"tip": "git clone https://github.com/user/repo.git --depth 1",
"category": "Basic Operations"
},
{
"title": "Search Commit log across all branches for given text",
"tip": "git log --all --grep='<given-text>'",
"category": "Log and History"
},
{
"title": "Get first commit in a branch (from master)",
"tip": "git log --oneline master..<branch-name> | tail -1",
"alternatives": [
"git log --reverse master..<branch-name> | head -6"
],
"category": "Log and History"
},
{
"title": "Unstaging Staged file",
"tip": "git reset HEAD <file-name>",
"category": "Undoing Changes"
},
{
"title": "Force push to Remote Repository",
"tip": "git push -f <remote-name> <branch-name>",
"category": "Basic Operations"
},
{
"title": "Adding Remote name",
"tip": "git remote add <remote-nickname> <remote-url>",
"category": "Remotes"
},
{
"title": "List all currently configured remotes",
"tip": "git remote -v",
"category": "Remotes"
},
{
"title": "Show the author, time and last revision made to each line of a given file",
"tip": "git blame <file-name>",
"category": "Log and History"
},
{
"title": "Group commits by authors and title",
"tip": "git shortlog",
"category": "Basic Operations"
},
{
"title": "Forced push but still ensure you don't overwrite other's work",
"tip": "git push --force-with-lease <remote-name> <branch-name>",
"category": "Basic Operations"
},
{
"title": "Show how many lines does an author contribute",
"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 }' -",
"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"
],
"category": "Log and History"
},
{
"title": "Revert: Reverting an entire merge",
"tip": "git revert -m 1 <commit-ish>",
"category": "Undoing Changes"
},
{
"title": "Number of commits in a branch",
"tip": "git rev-list --count <branch-name>",
"category": "Basic Operations"
},
{
"title": "Alias: git undo",
"tip": "git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'",
"category": "Setup and Config"
},
{
"title": "Add object notes",
"tip": "git notes add -m 'Note on the previous commit....'",
"category": "Basic Operations"
},
{
"title": "Show all the git-notes",
"tip": "git log --show-notes='*'",
"category": "Log and History"
},
{
"title": "Apply commit from another repository",
"tip": "git --git-dir=<source-dir>/.git format-patch -k -1 --stdout <SHA1> | git am -3 -k",
"category": "Basic Operations"
},
{
"title": "Specific fetch reference",
"tip": "git fetch origin master:refs/remotes/origin/mymaster",
"category": "Basic Operations"
},
{
"title": "Find common ancestor of two branches",
"tip": "git merge-base <branch-name> <other-branch-name>",
"category": "Merging and Rebasing"
},
{
"title": "List unpushed git commits",
"tip": "git log --branches --not --remotes",
"alternatives": [
"git log @{u}..",
"git cherry -v"
],
"category": "Log and History"
},
{
"title": "Add everything, but whitespace changes",
"tip": "git diff --ignore-all-space | git apply --cached",
"category": "Log and History"
},
{
"title": "Edit [local/global] git config",
"tip": "git config [--global] --edit",
"category": "Setup and Config"
},
{
"title": "blame on certain range",
"tip": "git blame -L <start>,<end>",
"category": "Log and History"
},
{
"title": "Show a Git logical variable.",
"tip": "git var -l | <variable>",
"category": "Log and History"
},
{
"title": "Preformatted patch file.",
"tip": "git format-patch -M upstream..topic",
"category": "Branching"
},
{
"title": "Get the repo name.",
"tip": "git rev-parse --show-toplevel",
"category": "Log and History"
},
{
"title": "logs between date range",
"tip": "git log --since='FEB 1 2017' --until='FEB 14 2017'",
"category": "Log and History"
},
{
"title": "Exclude author from logs",
"tip": "git log --perl-regexp --author='^((?!excluded-author-regex).*)$'",
"category": "Log and History"
},
{
"title": "Generates a summary of pending changes",
"tip": "git request-pull v1.0 https://git.ko.xz/project master:for-linus",
"category": "Basic Operations"
},
{
"title": "List references in a remote repository",
"tip": "git ls-remote git://git.kernel.org/pub/scm/git/git.git",
"category": "Remotes"
},
{
"title": "Backup untracked files.",
"tip": "git ls-files --others -i --exclude-standard | xargs zip untracked.zip",
"category": "Miscellaneous"
},
{
"title": "List all git aliases",
"tip": "git config -l | grep alias | sed 's/^alias\\.//g'",
"alternatives": [
"git config -l | grep alias | cut -d '.' -f 2"
],
"category": "Setup and Config"
},
{
"title": "Show git status short",
"tip": "git status --short --branch",
"category": "Basic Operations"
},
{
"title": "Checkout a commit prior to a day ago",
"tip": "git checkout master@{yesterday}",
"category": "Basic Operations"
},
{
"title": "Push the current branch to the same name on the remote repository",
"tip": "git push origin HEAD",
"category": "Basic Operations"
},
{
"title": "Push a new local branch to remote repository and track",
"tip": "git push -u origin <branch_name>",
"category": "Basic Operations"
},
{
"title": "Change a branch base",
"tip": "git rebase --onto <new_base> <old_base>",
"category": "Merging and Rebasing"
},
{
"title": "Use SSH instead of HTTPs for remotes",
"tip": "git config --global url.'git@github.com:'.insteadOf 'https://github.com/'",
"category": "Setup and Config"
},
{
"title": "Update a submodule to the latest commit",
"tip": "cd <path-to-submodule>\ngit pull origin <branch>\ncd <root-of-your-main-project>\ngit add <path-to-submodule>\ngit commit -m \"submodule updated\"",
"category": "Basic Operations"
},
{
"title": "Prevent auto replacing LF with CRLF",
"tip": "git config --global core.autocrlf false",
"category": "Setup and Config"
},
{
"title": "Refresh the list of remote branches",
"tip": "git remote update origin --prune",
"category": "Remotes"
},
{
"title": "View expanded details of changes in last commit",
"tip": "git show",
"category": "Log and History"
},
{
"title": "Send a collection of patches as emails",
"tip": "git send-email [<options>] <file|directory>\u2026\n\ngit send-email [<options>] <format-patch options>",
"category": "Miscellaneous"
},
{
"title": "Edit config for each level",
"tip": "git config --edit --system\n\ngit config --edit --global\n\ngit config --edit --local",
"category": "Setup and Config"
},
{
"title": "Visualize each position of HEAD in the last 30 days",
"tip": "git reflog",
"category": "Log and History"
},
{
"title": "Duplicating a repository",
"tip": "git clone --bare https://github.com/exampleuser/old-repository.git\n\ngit push --mirror https://github.com/exampleuser/new-repository.git",
"category": "Basic Operations"
},
{
"title": "Switch to a branch (modern alternative to checkout)",
"tip": "git switch <branch-name>",
"alternatives": [
"git switch -c <new-branch-name>"
],
"category": "Branching"
},
{
"title": "Restore file (modern alternative to reset/checkout --)",
"tip": "git restore <file-name>",
"alternatives": [
"git restore --staged <file-name>"
],
"category": "Undoing Changes"
}
]