10 Must Know Git Commands That Almost Nobody Knows

  Переглядів 94,174

Web Dev Simplified

Web Dev Simplified

День тому

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

КОМЕНТАРІ: 145
@stevebriggs6469
@stevebriggs6469 2 роки тому
git stash is also handy when you made changes in the wrong branch :) stash; change branch; stash pop
@KirkWaiblinger
@KirkWaiblinger 2 роки тому
Way more useful than the case he describes imo
@Pilecek
@Pilecek 2 роки тому
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 роки тому
l think every body knows 'rebase' command. :)
@nayakashu
@nayakashu 2 роки тому
rebase interactive is of great help
@Pilecek
@Pilecek 2 роки тому
@@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 роки тому
I don't know rebase :(
@mykalimba
@mykalimba 2 роки тому
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 роки тому
it depends, some bosses go with reflux
@ryanbobian1
@ryanbobian1 11 місяців тому
@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 2 роки тому
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.
@markbusnellijr.9948
@markbusnellijr.9948 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!
@russellblack4671
@russellblack4671 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.
@SevenEleven7II
@SevenEleven7II 2 роки тому
For the git-revert example, you should've shown how to revert a merge commit as that is very commonly the usecase
@LewiUberg
@LewiUberg 2 роки тому
Probably the best git tutorial I've seen the past year. To the point. Thanks!
@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!
@jamshediqbal7936
@jamshediqbal7936 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!
@IceMetalPunk
@IceMetalPunk 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!
@juancamacho479
@juancamacho479 2 роки тому
git cherry-pick is pretty good too
@waiwaitea
@waiwaitea 2 роки тому
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?
@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.
@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!
@manuelcasares7270
@manuelcasares7270 2 роки тому
Thanks, awesome video, please more git tutorials for the future!
@jacob_dmn
@jacob_dmn 2 роки тому
Very helpful, Kyle, thank you !
@TheMrFelin
@TheMrFelin 2 роки тому
Awesome video mate, thanks so much!
@traveller_pbuddy
@traveller_pbuddy 2 роки тому
Thanks for knowledge brother 👍
@jibaromar2249
@jibaromar2249 2 роки тому
That bisect command is amazing 👌
@shakedrosenblat1925
@shakedrosenblat1925 4 місяці тому
Absolutely amazing video. We want more of this please
@tomknudcognizant5746
@tomknudcognizant5746 2 роки тому
Great video rundown of the best git commands, thanks.
@MrMMohsen
@MrMMohsen 2 роки тому
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).
@bronxandbrenx
@bronxandbrenx 2 роки тому
I learned so much. I love this. :)
@ThorkilKowalski
@ThorkilKowalski 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 роки тому
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
@szpaklabs8893
@szpaklabs8893 2 роки тому
thank you, very useful! I should try debug with bisect
@sruthireddy1979
@sruthireddy1979 Рік тому
Very informative and quick video.... Thanks bro 👍
@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`.
@rubylily
@rubylily 2 роки тому
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
@azurnxo2134
@azurnxo2134 2 роки тому
Or shift +zz.
@TheParkitny
@TheParkitny 2 роки тому
+1 for bisect. Very useful, I'll be trying this out next time I break my code
@rollinOnCode
@rollinOnCode 2 роки тому
i did! thanks for saving my life and my career!
@prasadwalvekar
@prasadwalvekar 2 роки тому
Bisect and Reset!!! Thanks Kyle!
@plouf1969
@plouf1969 9 місяців тому
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.
@lucienchu9649
@lucienchu9649 2 роки тому
Crazy useful content, thanks
@sanfords
@sanfords 2 роки тому
Helpful for sure - you should emphasize that some of this won't work on windows without awk or xargs.
@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?
@transatlant1c
@transatlant1c 2 роки тому
git bisect reset
@someonewhowantedtobeahero3206
@someonewhowantedtobeahero3206 2 роки тому
Thanks. This is very interesting
@MrTimRJensen
@MrTimRJensen 2 роки тому
You oughta do a short on rebase. Best thing ever.
@FilipCodes
@FilipCodes 2 роки тому
Cool. Much needed video 🤓
@donnyroufs551
@donnyroufs551 2 роки тому
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 роки тому
@@donnyroufs551 not having a repo is even better
@arshdeepkumar2586
@arshdeepkumar2586 2 роки тому
or just using file system for code management
@donnyroufs551
@donnyroufs551 2 роки тому
@@arshdeepkumar2586 You must be on crack
@DVN_DVN
@DVN_DVN 2 роки тому
Basement Jaxx : "where's your head at ?" WDS : "hold my git ."
@ridl27
@ridl27 2 роки тому
bruh! recently I read your article and now we have a video :O
@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 роки тому
Thanks for the heads up. I will get that fixed.
@transatlant1c
@transatlant1c 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.
@deepfuchsia7204
@deepfuchsia7204 2 роки тому
Would be nice to see a video on working trees in git.
@nro337
@nro337 2 роки тому
Thank you!!
@JayHors
@JayHors 2 роки тому
Do you know if wildcards (*) behave like . or like -A when dealing with git add?
@Marty
@Marty 2 роки тому
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.
@cbn1362
@cbn1362 2 роки тому
If you like to do git in terminal my favorite is TIG! Cannot do a single commit without using tig now
@lorenzomijorus
@lorenzomijorus 2 роки тому
Lazygit Will handle all of this for you. Great video thought
@everyonecanbefascist
@everyonecanbefascist 2 роки тому
Tons of nuggets in this video!
@ashutoshthakur9542
@ashutoshthakur9542 2 роки тому
Next level ❤️❤️
@pguti778
@pguti778 2 роки тому
Please do version 2 of this video!!
@ellisj98
@ellisj98 2 роки тому
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 2 роки тому
Superbbbb...... video like other videos 😍
@josephlivengood4508
@josephlivengood4508 2 роки тому
That's easy to remember, what do you call cutting tree branches? Pruning
@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 роки тому
git bisect sounds amazingly powerful
@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
@mr.somebody646
@mr.somebody646 2 роки тому
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 роки тому
I already have a Node blog article and a separate user authentication Node video.
@mr.somebody646
@mr.somebody646 2 роки тому
@@WebDevSimplified 👍👍👍
@telegramgdrive4290
@telegramgdrive4290 2 роки тому
What shell are you using, is that wsl?
@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
@Arganoid
@Arganoid 2 роки тому
Do you ever use a graphical git client? Fork is very good
@alii4334
@alii4334 2 роки тому
(ctrl + l) for clearing the terminal
@lab_rat_z
@lab_rat_z 2 роки тому
Top 10 git pranks to do with your friends
@jonopens
@jonopens 2 роки тому
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.
@YuriiKratser
@YuriiKratser 2 роки тому
Thanks.
@sudhakardhayalan8874
@sudhakardhayalan8874 2 роки тому
@kyle For deleting a branch we can use git branch -D branchName
@rgraph
@rgraph 6 місяців тому
WRT to aliases - couldn't you also use bash aliases for this?
@kkomax7
@kkomax7 Рік тому
What about a completely new, in depth git tutorial remake, all in one.
@11WicToR11
@11WicToR11 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 роки тому
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
@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 роки тому
'git fetch -p origin' is a simpler way to remove branches from the local repository that were deleted in the remote repository.
@bipinmaharjan4090
@bipinmaharjan4090 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.
@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..
@Aezur20
@Aezur20 2 роки тому
wow... bisect is sick.
@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 роки тому
You can replace 11:45 by 'git fetch -p', much simpler 😊
@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'
@srinathsathyanath7435
@srinathsathyanath7435 2 роки тому
Kyle = Google ai in physical form
@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.
@noli-timere-crede-tantum
@noli-timere-crede-tantum 8 місяців тому
"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
@narendra_reddy
@narendra_reddy 2 роки тому
Hi
@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
@ukzuck
@ukzuck 2 роки тому
First one may be
@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 .
@MathieuGuignes
@MathieuGuignes 6 місяців тому
Wow.. do you ever take a 1-second break in your ongoing speech ?! 😂😂😂😂
@MiningForPies
@MiningForPies 2 роки тому
Git add . Adds everything in the current directly and below, not the current directory.
@Arabian_Epileptic
@Arabian_Epileptic 2 роки тому
18th
@aram5642
@aram5642 2 роки тому
What is your fav guitar chord?
@shoebilyas5368
@shoebilyas5368 2 роки тому
... that almost *nobody knew* 😉
@khizrshaikh9902
@khizrshaikh9902 2 роки тому
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.
@narutokunn
@narutokunn 2 роки тому
Watched the first 5 seconds. Answer is 149712.
@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"
@awfulChannel
@awfulChannel 2 роки тому
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
@kaynesheenan
@kaynesheenan 2 роки тому
omg.. so confusing
@maheshguptha9796
@maheshguptha9796 2 роки тому
I use dropbox instead of git Git is so confusing😁
Another 5 Must Know JavaScript Features That Almost Nobody Knows
22:42
Web Dev Simplified
Переглядів 212 тис.
13 Advanced (but useful) Git Techniques and Shortcuts
8:07
Fireship
Переглядів 876 тис.
Помилка,  яку зробило військове керівництво 🙄
01:00
Радіо Байрактар
Переглядів 263 тис.
11.브랜치 합치기 | 졸업프로젝트
1:43:43
얀모 yanmo
Переглядів 64
10 Tailwind Classes I Wish I Knew Earlier
13:31
Web Dev Simplified
Переглядів 145 тис.
Learn Git In 15 Minutes
15:59
Colt Steele
Переглядів 2 млн
Git MERGE vs REBASE: The Definitive Guide
9:39
The Modern Coder
Переглядів 45 тис.
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Переглядів 881 тис.
5+ Must Know HTML Tags That Almost Nobody Knows
15:33
Web Dev Simplified
Переглядів 611 тис.
How To Actually Get Hired In 2024
10:43
Web Dev Simplified
Переглядів 183 тис.
Git Branching and Merging - Detailed Tutorial
54:28
SuperSimpleDev
Переглядів 171 тис.