10 Must Know Git Commands That Almost Nobody Knows

Sdílet
Vložit
  • čas přidán 12. 08. 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

Komentáře • 145

  • @stevebriggs6469
    @stevebriggs6469 Před 2 lety +37

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

    • @KirkWaiblinger
      @KirkWaiblinger Před 2 lety +1

      Way more useful than the case he describes imo

  • @Pilecek
    @Pilecek Před 2 lety +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 Před 2 lety +2

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

    • @nayakashu
      @nayakashu Před 2 lety +8

      rebase interactive is of great help

    • @Pilecek
      @Pilecek Před 2 lety +3

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

    • @kyujong93
      @kyujong93 Před 2 lety

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

    • @gJonii
      @gJonii Před 2 lety +2

      I don't know rebase :(

  • @mykalimba
    @mykalimba Před 2 lety +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 Před 2 lety +3

      it depends, some bosses go with reflux

    • @ryanbobian1
      @ryanbobian1 Před rokem

      @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.

  • @siamrahman1409
    @siamrahman1409 Před 2 lety +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.

  • @juancamacho479
    @juancamacho479 Před 2 lety +12

    git cherry-pick is pretty good too

  • @markbusnellijr.9948
    @markbusnellijr.9948 Před 2 lety +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!

  • @IceMetalPunk
    @IceMetalPunk Před 2 lety +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!

  • @SevenEleven7II
    @SevenEleven7II Před 2 lety +10

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

  • @russellblack4671
    @russellblack4671 Před 2 lety +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.

  • @waiwaitea
    @waiwaitea Před 2 lety +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

  • @jamshediqbal7936
    @jamshediqbal7936 Před 2 lety +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 Před 2 lety

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

  • @codeWithJudah
    @codeWithJudah Před 2 lety

    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!

  • @MrMMohsen
    @MrMMohsen Před 2 lety +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).

  • @thisisatonofbs
    @thisisatonofbs Před 2 lety

    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.

  • @ThorkilKowalski
    @ThorkilKowalski Před 2 lety +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 Před 2 lety +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

  • @darkzennn
    @darkzennn Před 2 lety

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

  • @rubylily
    @rubylily Před 2 lety +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

  • @shakedrosenblat1925
    @shakedrosenblat1925 Před 8 měsíci

    Absolutely amazing video. We want more of this please

  • @TheParkitny
    @TheParkitny Před 2 lety

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

  • @manuelcasares7270
    @manuelcasares7270 Před 2 lety

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

  • @TheMrFelin
    @TheMrFelin Před 2 lety

    Awesome video mate, thanks so much!

  • @tomknudcognizant5746
    @tomknudcognizant5746 Před 2 lety

    Great video rundown of the best git commands, thanks.

  • @jacob_dmn
    @jacob_dmn Před 2 lety

    Very helpful, Kyle, thank you !

  • @jibaromar2249
    @jibaromar2249 Před 2 lety

    That bisect command is amazing 👌

  • @sruthireddy1979
    @sruthireddy1979 Před rokem

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

  • @plouf1969
    @plouf1969 Před rokem

    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.

  • @Marty
    @Marty Před 2 lety +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.

  • @szpaklabs8893
    @szpaklabs8893 Před 2 lety

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

  • @traveller_pbuddy
    @traveller_pbuddy Před 2 lety

    Thanks for knowledge brother 👍

  • @bronxandbrenx
    @bronxandbrenx Před 2 lety

    I learned so much. I love this. :)

  • @Ambalek
    @Ambalek Před 2 lety

    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`.

  • @lucienchu9649
    @lucienchu9649 Před 2 lety

    Crazy useful content, thanks

  • @prasadwalvekar
    @prasadwalvekar Před 2 lety

    Bisect and Reset!!! Thanks Kyle!

  • @Powerful-Manifestor-
    @Powerful-Manifestor- Před 2 lety

    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?

  • @rollinOnCode
    @rollinOnCode Před 2 lety

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

  • @DVN_DVN
    @DVN_DVN Před 2 lety

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

  • @MrTimRJensen
    @MrTimRJensen Před 2 lety

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

  • @someonewhowantedtobeahero3206

    Thanks. This is very interesting

  • @sanfords
    @sanfords Před 2 lety

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

  • @transatlant1c
    @transatlant1c Před 2 lety +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 Před 2 lety +7

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

  • @cbn1362
    @cbn1362 Před 2 lety +1

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

  • @diogosoares1309
    @diogosoares1309 Před 2 lety

    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!

  • @josephlivengood4508
    @josephlivengood4508 Před 2 lety

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

  • @ridl27
    @ridl27 Před 2 lety

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

  • @nro337
    @nro337 Před 2 lety

    Thank you!!

  • @pguti778
    @pguti778 Před 2 lety

    Please do version 2 of this video!!

  • @everyonecanbefascist
    @everyonecanbefascist Před 2 lety

    Tons of nuggets in this video!

  • @FilipCodes
    @FilipCodes Před 2 lety

    Cool. Much needed video 🤓

  • @clayton328
    @clayton328 Před 2 lety

    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.

  • @JayHors
    @JayHors Před 2 lety

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

  • @lorenzomijorus
    @lorenzomijorus Před 2 lety

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

  • @ellisj98
    @ellisj98 Před 2 lety +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.

  • @udittyagi9238
    @udittyagi9238 Před 2 lety

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

  • @deepfuchsia7204
    @deepfuchsia7204 Před 2 lety

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

  • @beinyourguard
    @beinyourguard Před 2 lety +1

    git bisect sounds amazingly powerful

  • @ashutoshthakur9542
    @ashutoshthakur9542 Před 2 lety

    Next level ❤️❤️

  • @lab_rat_z
    @lab_rat_z Před 2 lety

    Top 10 git pranks to do with your friends

  • @mr.somebody646
    @mr.somebody646 Před 2 lety +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  Před 2 lety +1

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

    • @mr.somebody646
      @mr.somebody646 Před 2 lety

      @@WebDevSimplified 👍👍👍

  • @jonopens
    @jonopens Před 2 lety +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.

  • @telegramgdrive4290
    @telegramgdrive4290 Před 2 lety

    What shell are you using, is that wsl?

  • @11WicToR11
    @11WicToR11 Před 2 lety +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 Před 2 lety +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.

  • @lorenkuhn3806
    @lorenkuhn3806 Před 2 lety

    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

  • @danielcir8675
    @danielcir8675 Před 2 lety

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

  • @Arganoid
    @Arganoid Před 2 lety

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

  • @YuriiKratser
    @YuriiKratser Před 2 lety

    Thanks.

  • @sudhakardhayalan8874
    @sudhakardhayalan8874 Před 2 lety

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

  • @rgraph
    @rgraph Před 10 měsíci

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

  • @kkomax7
    @kkomax7 Před rokem

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

  • @alii4334
    @alii4334 Před 2 lety

    (ctrl + l) for clearing the terminal

  • @AmaniTinbite
    @AmaniTinbite Před 18 dny

    Could you make a BASH video? 😃

  • @JimKernix
    @JimKernix Před 2 lety

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

  • @steveholder7289
    @steveholder7289 Před 2 lety

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

  • @M0rg1t0u
    @M0rg1t0u Před 2 lety +3

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

  • @deybmen
    @deybmen Před 2 lety

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

    • @ajjitsabat9786
      @ajjitsabat9786 Před 2 lety

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

    • @chrisgp1111
      @chrisgp1111 Před 2 lety +2

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

  • @Aezur20
    @Aezur20 Před 2 lety

    wow... bisect is sick.

  • @bopon4090
    @bopon4090 Před 2 lety

    Git dev simplified. 😁😁

  • @firedforfighting
    @firedforfighting Před 2 lety

    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..

  • @jamesrosemary2932
    @jamesrosemary2932 Před 2 lety

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

  • @srinathsathyanath7435
    @srinathsathyanath7435 Před 2 lety

    Kyle = Google ai in physical form

  • @r4ndsen
    @r4ndsen Před 2 lety

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

  • @MH-oc4de
    @MH-oc4de Před 2 lety

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

  •  Před 9 měsíci

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

  • @aram5642
    @aram5642 Před 2 lety

    What is your fav guitar chord?

  • @davecantera116
    @davecantera116 Před 2 lety

    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
    .

  • @narendra_reddy
    @narendra_reddy Před 2 lety

    Hi

  • @ReinkeDK
    @ReinkeDK Před 2 lety

    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 Před 2 lety

    First one may be

  • @KaaptnIglo
    @KaaptnIglo Před 2 lety

    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

  • @MiningForPies
    @MiningForPies Před 2 lety

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

  • @shoebilyas5368
    @shoebilyas5368 Před 2 lety

    ... that almost *nobody knew* 😉

  • @noli-timere-crede-tantum
    @noli-timere-crede-tantum Před 11 měsíci

    "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 Před 2 lety +1

    First I want heart

  • @narutokunn
    @narutokunn Před 2 lety

    Watched the first 5 seconds. Answer is 149712.

  • @Arabian_Abomination
    @Arabian_Abomination Před 2 lety

    18th

  • @awfulChannel
    @awfulChannel Před 2 lety +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

  • @ajjitsabat9786
    @ajjitsabat9786 Před 2 lety

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

    • @jodu
      @jodu Před 2 lety

      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 Před 2 lety

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

    • @jodu
      @jodu Před 2 lety

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

    • @ajjitsabat9786
      @ajjitsabat9786 Před 2 lety

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

    • @jodu
      @jodu Před 2 lety

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

  • @kaynesheenan
    @kaynesheenan Před 2 lety

    omg.. so confusing

  • @maheshguptha9796
    @maheshguptha9796 Před 2 lety

    I use dropbox instead of git
    Git is so confusing😁