13 Advanced (but useful) Git Techniques and Shortcuts

Fireship · Beginner ·🛠️ AI Tools & Apps ·4y ago

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 Angular 4 Development and Production Environments with Firebase
Angular 4 Development and Production Environments with Firebase
Fireship
2 OAuth with Angular and Firebase Tutorial
OAuth with Angular and Firebase Tutorial
Fireship
3 Anonymous Authentication with Angular and Firebase - Lazy Registration
Anonymous Authentication with Angular and Firebase - Lazy Registration
Fireship
4 Angular Router Guards for Firebase Users
Angular Router Guards for Firebase Users
Fireship
5 Angular Firebase CRUD App with NoSQL Database Tutorial
Angular Firebase CRUD App with NoSQL Database Tutorial
Fireship
6 Upload Files from Angular to Firebase Storage
Upload Files from Angular to Firebase Storage
Fireship
7 How to Deploy an Angular App to Firebase Hosting
How to Deploy an Angular App to Firebase Hosting
Fireship
8 Sharing Data between Components in Angular
Sharing Data between Components in Angular
Fireship
9 Loading Spinners for Asynchronous Firebase Data
Loading Spinners for Asynchronous Firebase Data
Fireship
10 Angular 4 Transactional Email with Google Firebase Cloud Functions
Angular 4 Transactional Email with Google Firebase Cloud Functions
Fireship
11 Firebase Database Rules Tutorial
Firebase Database Rules Tutorial
Fireship
12 Autocomplete Search with Angular4 and Firebase
Autocomplete Search with Angular4 and Firebase
Fireship
13 Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Fireship
14 Angular Drag-and-Drop File Uploads to Firebase Storage
Angular Drag-and-Drop File Uploads to Firebase Storage
Fireship
15 Text Translation with Firebase Cloud Functions onWrite and Angular 4
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Fireship
16 Custom Usernames with Firebase Authentication
Custom Usernames with Firebase Authentication
Fireship
17 Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Fireship
18 Simple Pagination with Firebase and Angular 4
Simple Pagination with Firebase and Angular 4
Fireship
19 How to Connect Firebase Users to their Data - 3 Methods
How to Connect Firebase Users to their Data - 3 Methods
Fireship
20 Add Toast Message Notifications to your Angular App
Add Toast Message Notifications to your Angular App
Fireship
21 Facebook-Inspired Reactions System with Angular and Firebase
Facebook-Inspired Reactions System with Angular and Firebase
Fireship
22 Learn NgModule in Angular with Examples
Learn NgModule in Angular with Examples
Fireship
23 Lazy Loading Components in Angular 4
Lazy Loading Components in Angular 4
Fireship
24 Stripe Checkout Payments with Angular and Firebase - Part 1
Stripe Checkout Payments with Angular and Firebase - Part 1
Fireship
25 Process Stripe Payments with Firebase Cloud Functions - Part 2
Process Stripe Payments with Firebase Cloud Functions - Part 2
Fireship
26 Selling Digital Content in Angular with Stripe Payments - Part 3
Selling Digital Content in Angular with Stripe Payments - Part 3
Fireship
27 Angular 4 Full Text Search with Algolia - Part 1
Angular 4 Full Text Search with Algolia - Part 1
Fireship
28 Algolia with Firebase Cloud Functions - Part 2
Algolia with Firebase Cloud Functions - Part 2
Fireship
29 Firebase Phone Authentication in Angular 4
Firebase Phone Authentication in Angular 4
Fireship
30 Top 7 RxJS Concepts for Angular Developers
Top 7 RxJS Concepts for Angular Developers
Fireship
31 Learn Angular Animations with 5 Examples
Learn Angular Animations with 5 Examples
Fireship
32 Advanced Firebase Data Filtering (Multi-Property)
Advanced Firebase Data Filtering (Multi-Property)
Fireship
33 Realtime Maps with Mapbox + Firebase + Angular
Realtime Maps with Mapbox + Firebase + Angular
Fireship
34 Angular Reactive Forms with Firebase Database Backend
Angular Reactive Forms with Firebase Database Backend
Fireship
35 Send Push Notifications in Angular with Firebase Cloud Messaging
Send Push Notifications in Angular with Firebase Cloud Messaging
Fireship
36 Top 7 Ways to Debug Angular 4 Apps
Top 7 Ways to Debug Angular 4 Apps
Fireship
37 Infinite Scroll with Angular and Firebase
Infinite Scroll with Angular and Firebase
Fireship
38 Use TypeScript with Firebase Cloud Functions
Use TypeScript with Firebase Cloud Functions
Fireship
39 Realtime Graphs and Charts with Plotly and Firebase
Realtime Graphs and Charts with Plotly and Firebase
Fireship
40 Role-Based User Permissions in Firebase
Role-Based User Permissions in Firebase
Fireship
41 User Presence System in Realtime - Online, Offline, Away
User Presence System in Realtime - Online, Offline, Away
Fireship
42 Location-based Queries with GeoFire and Angular Google Maps
Location-based Queries with GeoFire and Angular Google Maps
Fireship
43 Angular ngrx Redux Quick Start Tutorial
Angular ngrx Redux Quick Start Tutorial
Fireship
44 Angular Ngrx Effects with Firebase Database
Angular Ngrx Effects with Firebase Database
Fireship
45 Progressive Web Apps with Angular
Progressive Web Apps with Angular
Fireship
46 Angular Ngrx with Firebase Google OAuth User Authentication
Angular Ngrx with Firebase Google OAuth User Authentication
Fireship
47 RxJS Quick Start with Practical Examples
RxJS Quick Start with Practical Examples
Fireship
48 Send SMS Text Messages with Twilio and Firebase
Send SMS Text Messages with Twilio and Firebase
Fireship
49 Firebase Database Performance Profiling
Firebase Database Performance Profiling
Fireship
50 Native Desktop Apps with Angular and Electron
Native Desktop Apps with Angular and Electron
Fireship
51 Subscription Payments with Stripe, Angular, and Firebase
Subscription Payments with Stripe, Angular, and Firebase
Fireship
52 Firestore with AngularFire5 Quick Start Tutorial
Firestore with AngularFire5 Quick Start Tutorial
Fireship
53 Angular HTTP Client Quick Start Tutorial
Angular HTTP Client Quick Start Tutorial
Fireship
54 Google Sign-In with Firestore Custom User Data
Google Sign-In with Firestore Custom User Data
Fireship
55 Star Review System from Scratch with Firestore + Angular
Star Review System from Scratch with Firestore + Angular
Fireship
56 Angular Chatbot with Dialogflow (API.ai)
Angular Chatbot with Dialogflow (API.ai)
Fireship
57 Learn @ngrx/entity and Feature Modules
Learn @ngrx/entity and Feature Modules
Fireship
58 Infinite Scroll Pagination with Firestore
Infinite Scroll Pagination with Firestore
Fireship
59 Faster Firestore via Data Aggregation
Faster Firestore via Data Aggregation
Fireship
60 Contentful - CMS for Angular Progressive Web Apps
Contentful - CMS for Angular Progressive Web Apps
Fireship

This video teaches 13 advanced Git techniques and shortcuts to improve development workflow, including using git commit -am, creating aliases, and utilizing GitHub Code Spaces. By mastering these techniques, developers can become more productive and efficient in their work. The video also covers Git automation and workflow optimization using tools like husky and npm.

Key Takeaways
  1. Use git commit -am to skip git add
  2. Create aliases in git config
  3. Use git commit --amend to update the last commit
  4. Use git revert to go back to a previous state
  5. Use GitHub Code Spaces to access your repo from anywhere
  6. Use Git stash to save changes without committing them
  7. Use Git log with graph, one-line, and decorate options
  8. Use Git bisect to find the commit that introduced a bug
  9. Use fix up instead of squash when doing rebase
  10. Configure git hooks with husky
💡 Mastering advanced Git techniques and shortcuts can significantly improve development workflow and productivity, and utilizing tools like GitHub Code Spaces and husky can further optimize Git automation and workflow.

Related Reads

📰
Beyond 11,000: Navigating the Unified MCP Server Catalog That's Reshaping AI Tooling
Learn to navigate the Unified MCP Server Catalog with over 11,000 tools, reshaping AI tooling and streamlining development workflows
Dev.to · Robert Pelloni
📰
Could AI Save the English Major?
Explore how AI can enhance the English major curriculum and improve student learning outcomes
Medium · AI
📰
Six AI Tools Advancing Mental Health Care Access
Discover six AI tools revolutionizing mental health care access, enabling remote screenings and personalized support
Dev.to AI
📰
Runway Can’t Win on ‘Best Model’ Anymore. So It Stopped Trying To.
Runway launches Media Router, a tool that automatically selects the best image, shifting focus from 'best model' to practical solutions
Medium · AI

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
Up next
Clicky AI Telugu 🔥 Control Your Computer with Voice | Best Free AI Tool 2026
Withmesravani_
Watch →