13 Advanced (but useful) Git Techniques and Shortcuts
Key Takeaways
This video covers 13 advanced Git techniques and shortcuts, including using git commit -am, creating aliases, and utilizing GitHub Code Spaces, to supercharge development workflow.
Full Transcript
one of the best pieces of advice i ever got was get good at git few things are more scary for a software engineer than screwing something up with git after weeks of writing the perfect code you submit a pull request and end up with a bunch of embarrassing failed checks and merge conflicts next thing you know you're scrambling on stack overflow looking for a solution that will likely just add gasoline to the fire git was created by a guy much smarter than us he knew if he made it too easy it would make us weak instead he wanted to give us the glory of overcoming the challenge i'm pretty sure that's what he was thinking in today's video we'll look at a bunch of different tips and tricks to make you more productive with git but if you're new to git i just released a short course on fire fireship io that's designed as a modern learning path to get you started with git and github it contains a bunch of short videos along with exercises to transform you into a professional git user quickly this content is supported by viewers like you and i want to send a huge thank you to everybody out there who's already a pro member so to get started i'm assuming you know the basics of git like you know how to do a git ad followed by a git commit to save a snapshot of your code that's usually the first thing you learn in git but there's actually a better way to get the job done you can get rid of the git add and go straight to commit by using the am flag this will automatically add all the files in the current working directory that's a nice improvement but there's actually an even more concise way to get the job done your git config provides a way to create aliases which are commonly used to shorten existing commands or create your own new custom commands for example we might create an alias called ac that runs the add and commit command with just two letters that allows us to get things done faster but sometimes going fast leads to mistakes clearly mistakes were made what if you made a typo on your last commit message instead of resetting and creating a new commit the amend flag followed by a new message will simply update the latest commit or maybe you forgot to include or stage a couple files with your last commit you can also update the last commit with new files by using the amend flag and if you want to keep the same commit message add the no edit flag as well but keep in mind this only really works if you haven't already pushed your code to a remote repository unless you like to live dangerously in which case you can do a git push with the force flag this will overwrite the remote commit with the state of your local code however if there are commits on the remote branch that you don't have you will lose them forever and your co-workers might not be too happy about that don't make me swing on you bro but what happens if you push some code to a remote repository then realize it's complete garbage and never should have been there in the first place the git revert command allows you to take one commit and go back to the state that was there previously it's kind of like an undo but it doesn't remove the original commit from the history instead it just goes back to the original state and that's much easier than trying to put things back together like a trauma surgeon too much blood i can't see a thing in other cases you may need to work on a repo but not have access to your local machine if you're at your grandma's house without your laptop you can use any computer that has a web browser go to github and find the repo that you want to work on then hit the period key on your keyboard and like magic it pulls up a browser-based version of vs code where you can make edits submit pull requests and do almost anything else you could do locally well except for run the terminal if you do need to run terminal commands you can set up a github code space in the cloud which will give you the full power of vs code and is likely much faster than your grandma's computer but now let's switch gears to one of my favorite git commands stash have you ever spent time working on some changes that almost work but they can't really be committed yet because they break everything else or maybe it's just really sloppy and you don't want all your friends to see it yet git stash will remove the changes from your current working directory and save them for later use without committing them to the repo the simple way to use it is get stash and then get pop when you're ready to add those changes back into your code but if you use the command a lot you can use git stash save followed by a name to reference it later then when you're ready to work on it again use git stash list to find it then git stash apply with the corresponding index to use it now if you want to use a stash at grandma's house you're pretty much sol unless you use a github code space in which case your stashes would be saved in the cloud that's pretty cool but now i have a public service announcement for developers in the modern era historically the default branch in git is called the master branch but post 2020 this term is no longer the preferred nomenclature refer to it as main mega or mucho to stay out of trouble to change it use get branch followed by the m flag and rename it to main or maybe get creative and invent your own name now another command you're probably familiar with is git log to view a history of commits the problem with this command is that the output is harder and harder to read as your project grows in complexity to make the output more readable add the options of graph one line and decorate you can now see a more concise breakdown and how different branches connect together but if you're looking at the git log there's likely a commit in there that's currently breaking your app get bisect allows you to start from a commit that is known to have a bug likely the most recent commit but you knew that the app was working a few hours ago you can point bisect to the last known working commit then it performs a binary search to walk you through each commit in between if the commit looks good type bisect good to move on to the next commit eventually you'll find the bad one and know exactly which code needs to be fixed another advanced git technique that every developer should know is how to squash their commits imagine you're working on a feature branch that has three different commits and you're ready to merge it into the master branch i mean main branch but all these commit messages are kind of pointless and it would be better if it was just one single commit we can do that from our feature branch by running git rebase with the interactive option for the main branch that'll pull up a file with a list of commits on this branch if we want to use a commit we just use the pick command we can also change a message using the reword command or we can combine or squash everything into the original commit using squash go ahead and save the file and close it git will pull up another file prompting you to update the commit message which by default will be a combination of all the messages that you just squashed and if you don't like all the messages to be combined you can use fix up instead of squash when doing the rebase to be even more productive you can also use fix up and squash flags when making commits on your branch when you do that it tells git in advance that you want to squash them so when you go to do a rebase with the auto squash flag it can handle all the squashing automatically now if you maintain a repo one tool that can be very useful is get hooks whenever you perform an operation with git like a commit for example it creates an event and hooks allow you to run some code either before or after that event happens if you look in the hidden git directory you'll see a directory there called hooks and inside of it you'll find a bunch of different scripts that can be configured to run when different events in git happen if you happen to be a javascript developer there's a package called husky that makes it much easier to configure git hooks for example you might install it with npm then create a script that will validate or link your code before each commit and that can help improve your overall code quality to wrap things up let's talk about deleting things let's imagine you have a remote repository on github than a local version on your machine that you've been making changes to but things haven't been going too well and you just want to go back to the original state and the remote repo first do a git fetch to grab the latest code in the remote repo then use reset with the hard flag to override your local code with the remote code but be careful your local changes will be lost forever but you might still be left with some random untracked files or build artifacts here and there use the get clean command to remove those files as well but if you're sick of get at this point and want to just get rid of it all together maybe you want to try out apache subversion to change things up a bit all you have to do is delete that hidden git folder and you're on your own again oh and there's one other tip i almost forgot about that comes in really handy if you recently switched out of a branch and forgot its name you can use git checkout followed by a dash to go directly back into the previous branch that you were working on i'm going to go ahead and wrap things up there if you have any additional git tips make sure to leave them in the comments and if you want to master the fundamentals of git step by step check out the full course on fire ship io thanks for watching and i will see you in the next one
Original Description
Productive programmers tend to be really good at Git. Take a look at 13 advanced git tips and tricks to supercharge your development workflow. 🔥 Enroll in the New Full Git Course https://fireship.io/courses/git/
💰 Extra big 40% discount (expires in 1 week). Use code: oqBi9fWv
Upgrade to PRO at https://fireship.io/pro
#git #learntocode #tips
🔗 Resources
The Full Git & GitHub Course https://fireship.io/courses/git/
Git Docs https://git-scm.com/
Git in 100 Seconds https://youtu.be/hwP7WQkmECE
📚 Chapters
00:00 Git Started
00:59 Combine add & commit
01:20 Aliases
01:38 Amend
02:03 Force Push
02:24 Revert
02:47 Codespaces
03:21 Stash
04:05 PC Master Branch
04:27 Pretty Logs
04:51 Bisect
05:14 Autosquash
06:18 Hooks
06:58 Destroy Things
07:41 Checkout to Last
🎨 My Editor Settings
- Atom One Dark
- vscode-icons
- Fira Code Font
🏷️ Topics Covered
- Git Shortcuts
- Github Codespaces Cloud VSCode
- Software Version Control
- Dealing with Merge Conflicts
- Git Merge & Rebase
- How to Squash Commits
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Fireship · Fireship · 0 of 60
← Previous
Next →
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
Angular 4 Development and Production Environments with Firebase
Fireship
OAuth with Angular and Firebase Tutorial
Fireship
Anonymous Authentication with Angular and Firebase - Lazy Registration
Fireship
Angular Router Guards for Firebase Users
Fireship
Angular Firebase CRUD App with NoSQL Database Tutorial
Fireship
Upload Files from Angular to Firebase Storage
Fireship
How to Deploy an Angular App to Firebase Hosting
Fireship
Sharing Data between Components in Angular
Fireship
Loading Spinners for Asynchronous Firebase Data
Fireship
Angular 4 Transactional Email with Google Firebase Cloud Functions
Fireship
Firebase Database Rules Tutorial
Fireship
Autocomplete Search with Angular4 and Firebase
Fireship
Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Fireship
Angular Drag-and-Drop File Uploads to Firebase Storage
Fireship
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Fireship
Custom Usernames with Firebase Authentication
Fireship
Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Fireship
Simple Pagination with Firebase and Angular 4
Fireship
How to Connect Firebase Users to their Data - 3 Methods
Fireship
Add Toast Message Notifications to your Angular App
Fireship
Facebook-Inspired Reactions System with Angular and Firebase
Fireship
Learn NgModule in Angular with Examples
Fireship
Lazy Loading Components in Angular 4
Fireship
Stripe Checkout Payments with Angular and Firebase - Part 1
Fireship
Process Stripe Payments with Firebase Cloud Functions - Part 2
Fireship
Selling Digital Content in Angular with Stripe Payments - Part 3
Fireship
Angular 4 Full Text Search with Algolia - Part 1
Fireship
Algolia with Firebase Cloud Functions - Part 2
Fireship
Firebase Phone Authentication in Angular 4
Fireship
Top 7 RxJS Concepts for Angular Developers
Fireship
Learn Angular Animations with 5 Examples
Fireship
Advanced Firebase Data Filtering (Multi-Property)
Fireship
Realtime Maps with Mapbox + Firebase + Angular
Fireship
Angular Reactive Forms with Firebase Database Backend
Fireship
Send Push Notifications in Angular with Firebase Cloud Messaging
Fireship
Top 7 Ways to Debug Angular 4 Apps
Fireship
Infinite Scroll with Angular and Firebase
Fireship
Use TypeScript with Firebase Cloud Functions
Fireship
Realtime Graphs and Charts with Plotly and Firebase
Fireship
Role-Based User Permissions in Firebase
Fireship
User Presence System in Realtime - Online, Offline, Away
Fireship
Location-based Queries with GeoFire and Angular Google Maps
Fireship
Angular ngrx Redux Quick Start Tutorial
Fireship
Angular Ngrx Effects with Firebase Database
Fireship
Progressive Web Apps with Angular
Fireship
Angular Ngrx with Firebase Google OAuth User Authentication
Fireship
RxJS Quick Start with Practical Examples
Fireship
Send SMS Text Messages with Twilio and Firebase
Fireship
Firebase Database Performance Profiling
Fireship
Native Desktop Apps with Angular and Electron
Fireship
Subscription Payments with Stripe, Angular, and Firebase
Fireship
Firestore with AngularFire5 Quick Start Tutorial
Fireship
Angular HTTP Client Quick Start Tutorial
Fireship
Google Sign-In with Firestore Custom User Data
Fireship
Star Review System from Scratch with Firestore + Angular
Fireship
Angular Chatbot with Dialogflow (API.ai)
Fireship
Learn @ngrx/entity and Feature Modules
Fireship
Infinite Scroll Pagination with Firestore
Fireship
Faster Firestore via Data Aggregation
Fireship
Contentful - CMS for Angular Progressive Web Apps
Fireship
More on: Tool Use & Function Calling
View skill →Related Reads
Chapters (15)
Git Started
0:59
Combine add & commit
1:20
Aliases
1:38
Amend
2:03
Force Push
2:24
Revert
2:47
Codespaces
3:21
Stash
4:05
PC Master Branch
4:27
Pretty Logs
4:51
Bisect
5:14
Autosquash
6:18
Hooks
6:58
Destroy Things
7:41
Checkout to Last
🎓
Tutor Explanation
DeepCamp AI