10 Must Know Git Commands That Almost Nobody Knows

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ก.ค. 2024
  • My Blog: blog.webdevsimplified.com
    Git is complicated which is why most people only learn the basics, but if you spend the time to learn the more advanced features of Git you can really improve your skills as a developer. In this video I cover 10 of my favorite Git tips, tricks, and commands.
    📚 Materials/References:
    Git For Beginners Tutorial: • Learn Git in 20 Minutes
    10 Must Know Git Commands Article: blog.webdevsimplified.com/202...
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    ⏱️ Timestamps:
    00:00 - Introduction
    00:46 - Add/Commit Tips
    02:46 - Aliases
    05:02 - Revert
    06:32 - Reflog
    07:21 - Pretty Logs
    08:05 - Search Changes
    08:52 - Stash
    09:57 - Prune Branches
    12:03 - Bisect
    14:05 - Reset
    #GitHub #WDS #Git

ความคิดเห็น • 144

  • @stevebriggs6469
    @stevebriggs6469 2 ปีที่แล้ว +37

    git stash is also handy when you made changes in the wrong branch :) stash; change branch; stash pop

    • @KirkWaiblinger
      @KirkWaiblinger 2 ปีที่แล้ว +1

      Way more useful than the case he describes imo

  • @Pilecek
    @Pilecek 2 ปีที่แล้ว +88

    What a nice video. I’m bit suprised you didn’t add rebase -interactive, by my opinion is one of the most amazing and underused git commands.

    • @kyujong93
      @kyujong93 2 ปีที่แล้ว +2

      l think every body knows 'rebase' command. :)

    • @nayakashu
      @nayakashu 2 ปีที่แล้ว +8

      rebase interactive is of great help

    • @Pilecek
      @Pilecek 2 ปีที่แล้ว +3

      @@kyujong93 but did you try it with -interactive option? It is on another level!

    • @kyujong93
      @kyujong93 2 ปีที่แล้ว

      @@Pilecek oh I'll try that option! thank you :)

    • @gJonii
      @gJonii 2 ปีที่แล้ว +2

      I don't know rebase :(

  • @markbusnellijr.9948
    @markbusnellijr.9948 2 ปีที่แล้ว +2

    You can also `git reset --hard HASH` too if you need to reset your changes to a specific commit. I didn't know about `bisect` and that looks super helpful. Another great video Kyle!

  • @siamrahman1409
    @siamrahman1409 2 ปีที่แล้ว +3

    This is extremely useful stuff, I always find myself messing up using GIT because I never really took the time to learn the commands properly and simplify the commands.

  • @jamshediqbal7936
    @jamshediqbal7936 2 ปีที่แล้ว +2

    Very informative video. The good thing I learnt today is how to make aliases, especially for `git add .` followed by `git commit -m "some message"`. So, I really like the trick of `git ac "some message"`. It will surely save my time. Thank you Kyle!

  • @LewiUberg
    @LewiUberg 2 ปีที่แล้ว

    Probably the best git tutorial I've seen the past year. To the point. Thanks!

  • @mykalimba
    @mykalimba 2 ปีที่แล้ว +72

    The "reflog" in "git reflog" is short for "reference log". So, "ref-log" is a git command; "re-flog" is what your boss does to you when you once again miss your sprint deadline.

    • @joaquinel
      @joaquinel 2 ปีที่แล้ว +3

      it depends, some bosses go with reflux

    • @ryanbobian1
      @ryanbobian1 ปีที่แล้ว

      @mykalimba Hardly ever write comments but came here to point this out. Was going to say something along the lines of "bless you heart but mate, it's short hand for "reference log", lol @ re-flog." Then was like, no way someone else hasn't mentioned this, didn't even have to scroll to find the first occurence.

  • @russellblack4671
    @russellblack4671 2 ปีที่แล้ว +2

    Great video! I'm pretty sure that even after a git reset --hard, the commits still exist in your local repository, they are just no longer pointed to by HEAD or master, but they could still be referenced (and resurrected) by their commit hashes. The reflog is a history of which hashes were pointed to by HEAD in the past, so you can use that to identify the hash that HEAD pointed to before the commit.

  • @shakedrosenblat1925
    @shakedrosenblat1925 7 หลายเดือนก่อน

    Absolutely amazing video. We want more of this please

  • @TheMrFelin
    @TheMrFelin 2 ปีที่แล้ว

    Awesome video mate, thanks so much!

  • @tomknudcognizant5746
    @tomknudcognizant5746 2 ปีที่แล้ว

    Great video rundown of the best git commands, thanks.

  • @SevenEleven7II
    @SevenEleven7II 2 ปีที่แล้ว +10

    For the git-revert example, you should've shown how to revert a merge commit as that is very commonly the usecase

  • @darkzennn
    @darkzennn 2 ปีที่แล้ว

    Great video. Now that I'm working on a company, all this commands make more sense! Gonna create the git log --graph one!

  • @sruthireddy1979
    @sruthireddy1979 ปีที่แล้ว

    Very informative and quick video.... Thanks bro 👍

  • @thisisatonofbs
    @thisisatonofbs 2 ปีที่แล้ว

    There are also ways to prune local branches that were committed into a given branch. We use this weekly on the code base I work on at my job so that the overall git repositories stay clean. The nice thing is that it won't get rid of non-merged local branches, so changes you're still working on that haven't been pushed to the remote stay in place allowing one to continue working in them.

  • @codeWithJudah
    @codeWithJudah 2 ปีที่แล้ว

    Great video! the most important thing to remember is that everything is fixable, i see a lot of juniors get all stressed out over simple fixable mistakes so no worries :). Again, Awesome video!

  • @IceMetalPunk
    @IceMetalPunk 2 ปีที่แล้ว +2

    How have I gone all these years never knowing that git log has a content-search option? 😮 That is *so incredibly useful.* Same goes for bisect! Thank you for this video!

  • @waiwaitea
    @waiwaitea 2 ปีที่แล้ว +6

    honestly i haven't met most of the issue after i started to use gui version control, it is just so much better to look at visualize information

    • @sarcasticdna
      @sarcasticdna 2 ปีที่แล้ว

      Which one are you using?

  • @manuelcasares7270
    @manuelcasares7270 2 ปีที่แล้ว

    Thanks, awesome video, please more git tutorials for the future!

  • @jacob_dmn
    @jacob_dmn 2 ปีที่แล้ว

    Very helpful, Kyle, thank you !

  • @bronxandbrenx
    @bronxandbrenx 2 ปีที่แล้ว

    I learned so much. I love this. :)

  • @TheParkitny
    @TheParkitny 2 ปีที่แล้ว

    +1 for bisect. Very useful, I'll be trying this out next time I break my code

  • @rubylily
    @rubylily 2 ปีที่แล้ว +3

    my tip is use :x (or ZZ) to quit vim in those revert (and many other) situations. saves you 2 (or 3) keystrokes over :q!, probably many times over throughout your day

  • @szpaklabs8893
    @szpaklabs8893 2 ปีที่แล้ว

    thank you, very useful! I should try debug with bisect

  • @juancamacho479
    @juancamacho479 2 ปีที่แล้ว +12

    git cherry-pick is pretty good too

  • @traveller_pbuddy
    @traveller_pbuddy 2 ปีที่แล้ว

    Thanks for knowledge brother 👍

  • @jibaromar2249
    @jibaromar2249 2 ปีที่แล้ว

    That bisect command is amazing 👌

  • @lucienchu9649
    @lucienchu9649 2 ปีที่แล้ว

    Crazy useful content, thanks

  • @MrMMohsen
    @MrMMohsen 2 ปีที่แล้ว +4

    git reset doesn't actually delete commits when you reset to an old commit, because you still can reset to one of the later commits or cherry pick it. The way I see it is that the command just leaves the commits that you dropped dangling with no way to reach them unless you can refer to them through their SHA (short or full).

  • @Ambalek
    @Ambalek 2 ปีที่แล้ว

    Great video! You should be able to use ctrl-L to clear the terminal (or cmd-k in macOS to clear and forget scrollback, not sure if that works in VS Code), instead of typing `clear`.

  • @MrTimRJensen
    @MrTimRJensen 2 ปีที่แล้ว

    You oughta do a short on rebase. Best thing ever.

  • @prasadwalvekar
    @prasadwalvekar 2 ปีที่แล้ว

    Bisect and Reset!!! Thanks Kyle!

  • @rollinOnCode
    @rollinOnCode 2 ปีที่แล้ว

    i did! thanks for saving my life and my career!

  • @everyonecanbefascist
    @everyonecanbefascist 2 ปีที่แล้ว

    Tons of nuggets in this video!

  • @Powerful-Manifestor-
    @Powerful-Manifestor- 2 ปีที่แล้ว

    Such helpful tips and a clean explanation! Will definitely use bisect for debugging in future👍🏻 Just loved it! How to come out of the bisect mode though?

  • @someonewhowantedtobeahero3206
    @someonewhowantedtobeahero3206 2 ปีที่แล้ว

    Thanks. This is very interesting

  • @nro337
    @nro337 2 ปีที่แล้ว

    Thank you!!

  • @sanfords
    @sanfords 2 ปีที่แล้ว

    Helpful for sure - you should emphasize that some of this won't work on windows without awk or xargs.

  • @JayHors
    @JayHors 2 ปีที่แล้ว

    Do you know if wildcards (*) behave like . or like -A when dealing with git add?

  • @FilipCodes
    @FilipCodes 2 ปีที่แล้ว

    Cool. Much needed video 🤓

  • @plouf1969
    @plouf1969 ปีที่แล้ว

    I used git bisect, it's really awesome. The one caveat I have is that it sometimes is a bit annoying because you may have uncommitted code that you need in order to test if the bug is present, and if that code is in a tracked file, then git bisect will tell you to stash it (which you don't want to do). The solution is then to add an untracked file that lets you test, so git bisect won't complain.

  • @pguti778
    @pguti778 2 ปีที่แล้ว

    Please do version 2 of this video!!

  • @udittyagi9238
    @udittyagi9238 2 ปีที่แล้ว

    Superbbbb...... video like other videos 😍

  • @ashutoshthakur9542
    @ashutoshthakur9542 2 ปีที่แล้ว

    Next level ❤️❤️

  • @ridl27
    @ridl27 2 ปีที่แล้ว

    bruh! recently I read your article and now we have a video :O

  • @ThorkilKowalski
    @ThorkilKowalski 2 ปีที่แล้ว +2

    Instead of teaching people to stage all files in the directory, you should teach people to only stage and commit the changes they intend. That is done with `git add -p` and `git commit -v`.
    This is a good video about how *not* to use git.

    • @transatlant1c
      @transatlant1c 2 ปีที่แล้ว +1

      Just commented a similar thing. Doing commit -a or add . and unknowingly pushing in sensitive files like .env or logs that might have plaintext secrets in them sounds like a great way to leak data and loose your job 👍 not everyone knows how to setup gitignore properly and relying on it would be very foolish

  • @cbn1362
    @cbn1362 2 ปีที่แล้ว +1

    If you like to do git in terminal my favorite is TIG! Cannot do a single commit without using tig now

  • @deepfuchsia7204
    @deepfuchsia7204 2 ปีที่แล้ว

    Would be nice to see a video on working trees in git.

  • @DVN_DVN
    @DVN_DVN 2 ปีที่แล้ว

    Basement Jaxx : "where's your head at ?"
    WDS : "hold my git ."

  • @lorenzomijorus
    @lorenzomijorus 2 ปีที่แล้ว

    Lazygit Will handle all of this for you. Great video thought

  • @telegramgdrive4290
    @telegramgdrive4290 2 ปีที่แล้ว

    What shell are you using, is that wsl?

  • @transatlant1c
    @transatlant1c 2 ปีที่แล้ว +2

    Great tips overall, word of caution though - using git add . or -A could very very easily end up with junk or sensitive files being included in your repository, especially if your gitignore files aren't up to date.

  • @donnyroufs551
    @donnyroufs551 2 ปีที่แล้ว +7

    You can also automate bisect which is great when in combination with regression tests

    • @arshdeepkumar2586
      @arshdeepkumar2586 2 ปีที่แล้ว

      native is better

    • @donnyroufs551
      @donnyroufs551 2 ปีที่แล้ว

      @@arshdeepkumar2586 Not having a bad commit is even better.

    • @arshdeepkumar2586
      @arshdeepkumar2586 2 ปีที่แล้ว +2

      @@donnyroufs551 not having a repo is even better

    • @arshdeepkumar2586
      @arshdeepkumar2586 2 ปีที่แล้ว

      or just using file system for code management

    • @donnyroufs551
      @donnyroufs551 2 ปีที่แล้ว +2

      @@arshdeepkumar2586 You must be on crack

  • @diogosoares1309
    @diogosoares1309 2 ปีที่แล้ว

    Hey Kyle, you may want to amend the respective blog post.
    In section 2. Aliases you suggest adding the ac alias through the command:
    git config --global alias.ac "!git add -A && git commit -m"
    but double quotes won't make it. I came to the video to check which command you had run and you use single quotes. Just wanted to let you know as the blog posts do not take comments.
    Cheers man and keep up the awesome work!

    • @WebDevSimplified
      @WebDevSimplified  2 ปีที่แล้ว +1

      Thanks for the heads up. I will get that fixed.

  • @Marty
    @Marty 2 ปีที่แล้ว +1

    git reset actually does not delete anything. it just forces the tip of your current branch to a specific ref, be it a branch, tag, or commit. if you remembered the commit hash your branch was at before using git reset --hard origin/main, you could just do a git reset to your old commit hash. this works until these unreferenced commits are deleted from the graph via garbage collection.

  • @clayton328
    @clayton328 2 ปีที่แล้ว

    Every video Kyle makes, it's like he's sprinting through a marathon! So much useful information and detailed explanation crammed into a short amount of time.

  • @beinyourguard
    @beinyourguard 2 ปีที่แล้ว +1

    git bisect sounds amazingly powerful

  • @mr.somebody646
    @mr.somebody646 2 ปีที่แล้ว +1

    Can you make the video on node blog which has authentication and many other features like other has and also deploy a node application on AWS

    • @WebDevSimplified
      @WebDevSimplified  2 ปีที่แล้ว +1

      I already have a Node blog article and a separate user authentication Node video.

    • @mr.somebody646
      @mr.somebody646 2 ปีที่แล้ว

      @@WebDevSimplified 👍👍👍

  • @josephlivengood4508
    @josephlivengood4508 2 ปีที่แล้ว

    That's easy to remember, what do you call cutting tree branches? Pruning

  • @YuriiKratser
    @YuriiKratser 2 ปีที่แล้ว

    Thanks.

  • @danielcir8675
    @danielcir8675 2 ปีที่แล้ว

    Hey Kyle, the aliases work only on the PC you set up or are associated with your GitHub account? Thanks!

    • @wouterschols3345
      @wouterschols3345 2 ปีที่แล้ว

      Related to your pc, it is not shared

  • @ellisj98
    @ellisj98 2 ปีที่แล้ว +1

    I think you need to mention that doing git add for all files is not always the best way to add files. Sometimes you are working on a complex feature and it is important to commit little and often.

  • @rgraph
    @rgraph 9 หลายเดือนก่อน

    WRT to aliases - couldn't you also use bash aliases for this?

  • @Arganoid
    @Arganoid 2 ปีที่แล้ว

    Do you ever use a graphical git client? Fork is very good

  • @jonopens
    @jonopens 2 ปีที่แล้ว +1

    The git alias seems unnecessary when you can create aliases directly in your .rc file of choice and then persist then in a github repo to quickly pull onto any new machine. Just to make things even more trivial, if you are using something like oh-my-zsh, a lot of convenient git aliases are built in - you don't even need to write them yourself.

  • @lab_rat_z
    @lab_rat_z 2 ปีที่แล้ว

    Top 10 git pranks to do with your friends

  • @deybmen
    @deybmen 2 ปีที่แล้ว

    11:29 what's the difference of this and using git fetch --prune ?

    • @ajjitsabat9786
      @ajjitsabat9786 2 ปีที่แล้ว

      both are same it just removes the remote branch from the .git subfolder

    • @chrisgp1111
      @chrisgp1111 2 ปีที่แล้ว +2

      'git fetch -p origin' is a simpler way to remove branches from the local repository that were deleted in the remote repository.

  • @sudhakardhayalan8874
    @sudhakardhayalan8874 2 ปีที่แล้ว

    @kyle For deleting a branch we can use
    git branch -D branchName

  • @alii4334
    @alii4334 2 ปีที่แล้ว

    (ctrl + l) for clearing the terminal

  • @lorenkuhn3806
    @lorenkuhn3806 2 ปีที่แล้ว

    git reset does not really delete commits, it deletes references. The commits themselves still exist until the repo is eventually (automatically) purged in a cleanup.
    If you mistakenly do a reset, you can still list or search the unreferenced commits

  • @Aezur20
    @Aezur20 2 ปีที่แล้ว

    wow... bisect is sick.

  • @bopon4090
    @bopon4090 2 ปีที่แล้ว

    Git dev simplified. 😁😁

  • @steveholder7289
    @steveholder7289 2 ปีที่แล้ว

    Bisect. Never knew that one. Makes me want to write a bug just so I can use it.

  • @kkomax7
    @kkomax7 ปีที่แล้ว

    What about a completely new, in depth git tutorial remake, all in one.

  • @firedforfighting
    @firedforfighting 2 ปีที่แล้ว

    I came to this thinking I would know all of them all LMFAO..Search/bisect/prune I didn't even check for...I can't wait to explore bisect further it sounds like a game-changer for me..I wrote a very similar alias to delete all braches except main as well...I feel like I am more productive squashing my local feature branch commits into 1 commit before merging with main..this way I commit way more because I don't have to care about the commit messages until I am ready to merge..

  • @11WicToR11
    @11WicToR11 2 ปีที่แล้ว +2

    I think he went too fast over that prune branch command. What awk does there is: match all lines containing ": gone" and print first "word", meaning stuff until first space. Since this operates on lines (maybe you had 10 branches and 3 have that string ": gone"), it spits out 3 lines. We then need to use xargs which basically takes each line and runs command "git branch -d" followed by that line. So at the end he ran "git branch -d 21-25".
    Oneliners like these can be usefull without knowing how it works, but this is beauty of unix tools. You can combine them to do anything, since everything is basically files, lines of text and only your imagination is the limit.

    • @KurtvonLaven0
      @KurtvonLaven0 2 ปีที่แล้ว +1

      All true. Worth noting that there's no need to pipe anything at all. You can simply use one command to do the same thing in many cases: git remote prune origin.

  • @JimKernix
    @JimKernix 2 ปีที่แล้ว

    You need to scroll up so what you are typing is not blocked by the video controls

  • @jamesrosemary2932
    @jamesrosemary2932 2 ปีที่แล้ว

    On Windows command line, use double quote instead of single quote, otherwise parameters to git command will not work as expected.

  • @M0rg1t0u
    @M0rg1t0u 2 ปีที่แล้ว +3

    You can replace 11:45 by 'git fetch -p', much simpler 😊

  • @srinathsathyanath7435
    @srinathsathyanath7435 2 ปีที่แล้ว

    Kyle = Google ai in physical form

  • @r4ndsen
    @r4ndsen 2 ปีที่แล้ว

    you dont need to separate -a and -m. -am works fine

  • @MH-oc4de
    @MH-oc4de 2 ปีที่แล้ว

    It's even easier: >git commit -am 'message'

  • @narendra_reddy
    @narendra_reddy 2 ปีที่แล้ว

    Hi

  •  8 หลายเดือนก่อน

    Wow.. do you ever take a 1-second break in your ongoing speech ?! 😂😂😂😂

  • @ReinkeDK
    @ReinkeDK 2 ปีที่แล้ว

    Cool video.
    But you should really warn people about 'stash'.
    It's 1 stash per repository, not per stack.
    So if you are not careful, you delete your work.
    Personally i prefer commit any day, because it's safer.

  • @ukzuck
    @ukzuck 2 ปีที่แล้ว

    First one may be

  • @KaaptnIglo
    @KaaptnIglo 2 ปีที่แล้ว

    git bisect only works on the top of the working tree... you can ONLY do it on main, not on branches. Or did I understand it wrong?
    This makes it basically useless to me, as when I push something on main, it's usually quite clean :( Quite disappointed

  • @aram5642
    @aram5642 2 ปีที่แล้ว

    What is your fav guitar chord?

  • @davecantera116
    @davecantera116 2 ปีที่แล้ว

    A Great example of why software that is published has really nice features in one version that future versions don't have cause a new branch is created...
    While git is a good tool andIlove your video instructions, your quick paced diatribe on this video just sounds like double talk...
    This reverses the previous reverses, lol
    .

  • @Arabian_Epileptic
    @Arabian_Epileptic 2 ปีที่แล้ว

    18th

  • @MiningForPies
    @MiningForPies 2 ปีที่แล้ว

    Git add . Adds everything in the current directly and below, not the current directory.

  • @shoebilyas5368
    @shoebilyas5368 2 ปีที่แล้ว

    ... that almost *nobody knew* 😉

  • @narutokunn
    @narutokunn 2 ปีที่แล้ว

    Watched the first 5 seconds. Answer is 149712.

  • @noli-timere-crede-tantum
    @noli-timere-crede-tantum 10 หลายเดือนก่อน

    "I've done it countless times" -- doesn't sound very inspiring when the teacher accidentally deletes his work without knowing how to get it back

  • @khizrshaikh9902
    @khizrshaikh9902 2 ปีที่แล้ว +1

    First I want heart

  • @unknownunknown-us5ml
    @unknownunknown-us5ml 2 ปีที่แล้ว

    Makes a video about git… proceeds to execute advanced shell commands.
    Also if you’re looking to really screw yourself, use git stash the way that’s presented in this video.

  • @kaynesheenan
    @kaynesheenan 2 ปีที่แล้ว

    omg.. so confusing

  • @ajjitsabat9786
    @ajjitsabat9786 2 ปีที่แล้ว

    you are wrong i knew all the commands except adding multiple git commands as alias

    • @jodu
      @jodu 2 ปีที่แล้ว

      But then he isn't wrong because the alias thing is something you do not know and he said ALMOST nobody! So there is a chance that somebody knows this! :)

    • @ajjitsabat9786
      @ajjitsabat9786 2 ปีที่แล้ว

      @@jodu adding multiple git commands as alias is still useless as you can run both the commands individually

    • @jodu
      @jodu 2 ปีที่แล้ว

      @@ajjitsabat9786 No not really cause the config thing with the alias is also a git command...

    • @ajjitsabat9786
      @ajjitsabat9786 2 ปีที่แล้ว

      @@jodu with great powers comes great responsibilites if you know what you are doing then go ahead :)

    • @jodu
      @jodu 2 ปีที่แล้ว

      @@ajjitsabat9786 I think I know but you can also go ahead and again it's "Almost Nobody"

  • @sanjivgautam9063
    @sanjivgautam9063 2 ปีที่แล้ว

    I don't really think all of them are " must know ". git stash and git revert are " must know " ones. Rest, I highly doubt

  • @awfulChannel
    @awfulChannel 2 ปีที่แล้ว +1

    tbh finding a bug by traveling through a commit history doesn't seems to be a good idea. If you need git for this rather then the code itself it means you are not quite understand what you are debugging.
    P.S. thanks for log -S