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
2024-02-04T05:45:50.702Z
nova-2
2-general-nova
2024-01-09.29447
30089e05-99d1-4376-b32e-c263170674af
33f5d8d6-acad-4f99-8992-3b8e04b28be8
154e8d01a05d9a5543a2c6315913e6912da62ca3d587e61d45d64dc5e6bda032
67875a7f-c9c4-48a0-aa55-5bdb8a91c34a
deprecated
One of the best pieces of advice I ever got was git 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 and 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 and tips and tricks to make you more productive with Git.
But if you're new to Git, I just released a short course on 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 wanna 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 add 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 way to get the job done.
You can get rid of the git add and go straight to commit by using the a m 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, this is, which are commonly used to shorten existing commands or create your own new custom commands.
For example, we might create an alias called a c e, 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 we'll lose them forever.
And your coworkers 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 version.
I made your trouble.
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 wanna work on, then hit the period key on your keyboard.
And like magic, it pulls up a browser based version of Versus 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 Versus 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 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 git stash and then git 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 wanna use a stash at grandma's house, you're pretty much s o l, unless you use a GitHub Codespace, 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 git 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, oneline, 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.
Git 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 their advanced Git technique that every developer should know is how to squash their commits.
Imagine you're working on a feature branch that has 3 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 that pick command.
We can also change a message using the reword command, or we can combine or squash everything into that original commit using and 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 squash.
And if you don't like all the messages to be combined, you can use fixup instead of squash when doing the rebase.
To be even more productive, you can also use fixup 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 git hooks.
Whenever you perform an operation with git, like a commit for example, well, 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 it happened.
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 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, then a local version on your machine that you've been making changes to, but things haven't been going well, and you just want to go back to the original state in the remote repo.
1st, 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 git clean command to remove those files as well.
But if you're sick of git at this point and want to just get rid of it altogether, maybe you wanna 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 gonna 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 demos of Git step by step, check out the full course on FireShip IO.
Thanks for watching, and I will see you in the next one.

Speaker 0: One of the best pieces of advice I ever got was git 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 and 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 and tips and tricks to make you more productive with Git. But if you're new to Git, I just released a short course on 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 wanna 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 add 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 way to get the job done. You can get rid of the git add and go straight to commit by using the a m 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, this is, which are commonly used to shorten existing commands or create your own new custom commands. For example, we might create an alias called a c e, 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 we'll lose them forever. And your coworkers 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 version. I made your trouble. 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 wanna work on, then hit the period key on your keyboard. And like magic, it pulls up a browser based version of Versus 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 Versus 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 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 git stash and then git 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 wanna use a stash at grandma's house, you're pretty much s o l, unless you use a GitHub Codespace, 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 git 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, oneline, 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. Git 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 their advanced Git technique that every developer should know is how to squash their commits. Imagine you're working on a feature branch that has 3 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 that pick command. We can also change a message using the reword command, or we can combine or squash everything into that original commit using and 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 squash. And if you don't like all the messages to be combined, you can use fixup instead of squash when doing the rebase. To be even more productive, you can also use fixup 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 git hooks. Whenever you perform an operation with git, like a commit for example, well, 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 it happened. 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 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, then a local version on your machine that you've been making changes to, but things haven't been going well, and you just want to go back to the original state in the remote repo. 1st, 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 git clean command to remove those files as well. But if you're sick of git at this point and want to just get rid of it altogether, maybe you wanna 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 gonna 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 demos of Git step by step, check out the full course on FireShip IO.

Thanks for watching, and I will see you in the next one.
One of the best pieces of advice I ever got was git 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 and 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 and tips and tricks to make you more productive with Git.
But if you're new to Git, I just released a short course on 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 wanna 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 add followed by a git commit to save a snapshot of your code.
software development
software
That's usually the first thing you learn in git, but there's actually a better way way to get the job done. You can get rid of the git add and go straight to commit by using the a m 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, this is, which are commonly used to shorten existing commands or create your own new custom commands. For example, we might create an alias called a c e, 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 we'll lose them forever. And your coworkers 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 version. I made your trouble. 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 wanna work on, then hit the period key on your keyboard. And like magic, it pulls up a browser based version of Versus 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 Versus 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 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 git stash and then git 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 wanna use a stash at grandma's house, you're pretty much s o l, unless you use a GitHub Codespace, 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.
government
To change it, use git 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, oneline, 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. Git 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 their advanced Git technique that every developer should know is how to squash their commits. Imagine you're working on a feature branch that has 3 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 that pick command. We can also change a message using the reword command, or we can combine or squash everything into that original commit using and 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 squash. And if you don't like all the messages to be combined, you can use fixup instead of squash when doing the rebase. To be even more productive, you can also use fixup 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 git hooks. Whenever you perform an operation with git, like a commit for example, well, 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 it happened.
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 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.
software development
software
To wrap things up, let's talk about deleting things. Let's imagine you have a remote repository on GitHub, then a local version on your machine that you've been making changes to, but things haven't been going well, and you just want to go back to the original state in the remote repo. 1st, 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 git clean command to remove those files as well. But if you're sick of git at this point and want to just get rid of it altogether, maybe you wanna 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 gonna 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 demos of Git step by step, check out the full course on FireShip IO. Thanks for watching, and I will see you in the next one.
One of the best pieces of advice I ever got was git 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 and 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 and tips and tricks to make you more productive with Git. But if you're new to Git, I just released a short course on 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 wanna 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 add 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 way to get the job done. You can get rid of the git add and go straight to commit by using the a m 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, this is, which are commonly used to shorten existing commands or create your own new custom commands. For example, we might create an alias called a c e, 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 we'll lose them forever. And your coworkers 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 version. I made your trouble. 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 wanna work on, then hit the period key on your keyboard. And like magic, it pulls up a browser based version of Versus 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 Versus 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 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 git stash and then git 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 wanna use a stash at grandma's house, you're pretty much s o l, unless you use a GitHub Codespace, 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 git 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, oneline, 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. Git 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 their advanced Git technique that every developer should know is how to squash their commits. Imagine you're working on a feature branch that has 3 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 that pick command. We can also change a message using the reword command, or we can combine or squash everything into that original commit using and 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 squash. And if you don't like all the messages to be combined, you can use fixup instead of squash when doing the rebase. To be even more productive, you can also use fixup 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 git hooks. Whenever you perform an operation with git, like a commit for example, well, 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 it happened. 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 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, then a local version on your machine that you've been making changes to, but things haven't been going well, and you just want to go back to the original state in the remote repo. 1st, 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 git clean command to remove those files as well. But if you're sick of git at this point and want to just get rid of it altogether, maybe you wanna 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 gonna 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 demos of Git step by step, check out the full course on FireShip IO. Thanks for watching, and I will see you in the next one.
One
one
of
of
the
the
best
best
pieces
pieces
of
of
advice
advice
I
i
ever
ever
got
got
was
was
git
git
good
good
at
at
git.
git
Few
few
things
things
are
are
more
more
scary
scary
for
for
a
a
software
software
engineer
engineer
than
than
screwing
screwing
something
something
up
up
with
with
git.
git
After
after
weeks
weeks
of
of
writing
writing
the
the
perfect
perfect
code,
code
you
you
submit
submit
a
a
pull
pull
request
request
and
and
end
end
up
up
with
with
a
a
bunch
bunch
of
of
embarrassing
embarrassing
failed
failed
checks
checks
and
and
merge
merge
conflicts.
conflicts
Next
next
thing
thing
you
you
know,
know
you're
you're
scrambling
scrambling
on
on
Stack
stack
Overflow
overflow
looking
looking
for
for
a
a
solution
solution
and
and
that
that
will
will
likely
likely
just
just
add
add
gasoline
gasoline
to
to
the
the
fire,
fire
Git
git
was
was
created
created
by
by
a
a
guy
guy
much
much
smarter
smarter
than
than
us.
us
He
he
knew
knew
if
if
he
he
made
made
it
it
too
too
easy,
easy
it
it
would
would
make
make
us
us
weak.
weak
Instead,
instead
he
he
wanted
wanted
to
to
give
give
us
us
the
the
glory
glory
of
of
overcoming
overcoming
the
the
challenge.
challenge
I'm
i'm
pretty
pretty
sure
sure
that's
that's
what
what
he
he
was
was
thinking.
thinking
In
in
today's
today's
video,
video
we'll
we'll
look
look
at
at
a
a
bunch
bunch
of
of
and
and
tips
tips
and
and
tricks
tricks
to
to
make
make
you
you
more
more
productive
productive
with
with
Git.
git
But
but
if
if
you're
you're
new
new
to
to
Git,
git
I
i
just
just
released
released
a
a
short
short
course
course
on
on
Fireship
fireship
IO
io
that's
that's
designed
designed
as
as
a
a
modern
modern
learning
learning
path
path
to
to
get
get
you
you
started
started
with
with
Git
git
and
and
GitHub.
github
It
it
contains
contains
a
a
bunch
bunch
of
of
short
short
videos
videos
along
along
with
with
exercises
exercises
to
to
transform
transform
you
you
into
into
a
a
professional
professional
Git
git
user
user
quickly.
quickly
This
this
content
content
is
is
supported
supported
by
by
viewers
viewers
like
like
you,
you
and
and
I
i
wanna
wanna
send
send
a
a
huge
huge
thank
thank
you
you
to
to
everybody
everybody
out
out
there
there
who's
who's
already
already
a
a
pro
pro
member.
member
So
so
to
to
get
get
started,
started
I'm
i'm
assuming
assuming
you
you
know
know
the
the
basics
basics
of
of
Git,
git
like
like
you
you
know
know
how
how
to
to
do
do
a
a
git
git
add
add
followed
followed
by
by
a
a
git
git
commit
commit
to
to
save
save
a
a
snapshot
snapshot
of
of
your
your
code.
code
That's
that's
usually
usually
the
the
first
first
thing
thing
you
you
learn
learn
in
in
git,
git
but
but
there's
there's
actually
actually
a
a
better
better
way
way
way
way
to
to
get
get
the
the
job
job
done.
done
You
you
can
can
get
get
rid
rid
of
of
the
the
git
git
add
add
and
and
go
go
straight
straight
to
to
commit
commit
by
by
using
using
the
the
a
a
m
m
flag.
flag
This
this
will
will
automatically
automatically
add
add
all
all
the
the
files
files
in
in
the
the
current
current
working
working
directory.
directory
That's
that's
a
a
nice
nice
improvement,
improvement
but
but
there's
there's
actually
actually
an
an
even
even
more
more
concise
concise
way
way
to
to
get
get
the
the
job
job
done.
done
Your
your
git
git
config
config
provides
provides
a
a
way
way
to
to
create
create
aliases,
aliases
this
this
is,
is
which
which
are
are
commonly
commonly
used
used
to
to
shorten
shorten
existing
existing
commands
commands
or
or
create
create
your
your
own
own
new
new
custom
custom
commands.
commands
For
for
example,
example
we
we
might
might
create
create
an
an
alias
alias
called
called
a
a
c
c
e,
e
that
that
runs
runs
the
the
add
add
and
and
commit
commit
command
command
with
with
just
just
two
two
letters.
letters
That
that
allows
allows
us
us
to
to
get
get
things
things
done
done
faster,
faster
but
but
sometimes
sometimes
going
going
fast
fast
leads
leads
to
to
mistakes.
mistakes
Clearly,
clearly
mistakes
mistakes
were
were
made.
made
What
what
if
if
you
you
made
made
a
a
typo
typo
on
on
your
your
last
last
commit
commit
message?
message
Instead
instead
of
of
resetting
resetting
and
and
creating
creating
a
a
new
new
commit,
commit
the
the
amend
amend
flag
flag
followed
followed
by
by
a
a
new
new
message
message
will
will
simply
simply
update
update
the
the
latest
latest
commit,
commit
or
or
maybe
maybe
you
you
forgot
forgot
to
to
include
include
or
or
stage
stage
a
a
couple
couple
files
files
with
with
your
your
last
last
commit.
commit
You
you
can
can
also
also
update
update
the
the
last
last
commit
commit
with
with
new
new
files
files
by
by
using
using
the
the
amend
amend
flag,
flag
and
and
if
if
you
you
want
want
to
to
keep
keep
the
the
same
same
commit
commit
message,
message
add
add
the
the
no
no
edit
edit
flag
flag
as
as
well.
well
But
but
keep
keep
in
in
mind,
mind
this
this
only
only
really
really
works
works
if
if
you
you
haven't
haven't
already
already
pushed
pushed
your
your
code
code
to
to
a
a
remote
remote
repository,
repository
unless
unless
you
you
like
like
to
to
live
live
dangerously.
dangerously
In
in
which
which
case,
case
you
you
can
can
do
do
a
a
git
git
push
push
with
with
the
the
force
force
flag.
flag
This
this
will
will
overwrite
overwrite
the
the
remote
remote
commit
commit
with
with
the
the
state
state
of
of
your
your
local
local
code.
code
However,
however
if
if
there
there
are
are
commits
commits
on
on
the
the
remote
remote
branch
branch
that
that
you
you
don't
don't
have,
have
you
you
we'll
we'll
lose
lose
them
them
forever.
forever
And
and
your
your
coworkers
coworkers
might
might
not
not
be
be
too
too
happy
happy
about
about
that.
that
Don't
don't
make
make
me
me
swing
swing
on
on
you,
you
bro.
bro
But
but
what
what
happens
happens
if
if
you
you
push
push
some
some
code
code
to
to
a
a
remote
remote
repository,
repository
then
then
realize
realize
it's
it's
complete
complete
garbage
garbage
and
and
never
never
should
should
have
have
been
been
there
there
in
in
the
the
first
first
place.
place
The
the
git
git
revert
revert
command
command
allows
allows
you
you
to
to
take
take
one
one
commit
commit
and
and
go
go
back
back
to
to
the
the
state
state
that
that
was
was
there
there
previously.
previously
It's
it's
kind
kind
of
of
like
like
an
an
undo,
undo
but
but
it
it
doesn't
doesn't
remove
remove
the
the
original
original
commit
commit
from
from
the
the
history.
history
Instead,
instead
it
it
just
just
goes
goes
back
back
to
to
the
the
original
original
state
state
and
and
that's
that's
much
much
easier
easier
than
than
trying
trying
to
to
put
put
things
things
back
back
together
together
like
like
a
a
trauma
trauma
version.
version
I
i
made
made
your
your
trouble.
trouble
Too
too
much
much
blood.
blood
I
i
can't
can't
see
see
a
a
thing.
thing
In
in
other
other
cases,
cases
you
you
may
may
need
need
to
to
work
work
on
on
a
a
repo,
repo
but
but
not
not
have
have
access
access
to
to
your
your
local
local
machine.
machine
If
if
you're
you're
at
at
your
your
grandma's
grandma's
house
house
without
without
your
your
laptop,
laptop
you
you
can
can
use
use
any
any
computer
computer
that
that
has
has
a
a
web
web
browser.
browser
Go
go
to
to
GitHub
github
and
and
find
find
the
the
repo
repo
that
that
you
you
wanna
wanna
work
work
on,
on
then
then
hit
hit
the
the
period
period
key
key
on
on
your
your
keyboard.
keyboard
And
and
like
like
magic,
magic
it
it
pulls
pulls
up
up
a
a
browser
browser
based
based
version
version
of
of
Versus
versus
Code
code
where
where
you
you
can
can
make
make
edits,
edits
submit
submit
pull
pull
requests,
requests
and
and
do
do
almost
almost
anything
anything
else
else
you
you
could
could
do
do
locally.
locally
Well,
well
except
except
for
for
run
run
the
the
terminal.
terminal
If
if
you
you
do
do
need
need
to
to
run
run
terminal
terminal
commands,
commands
you
you
can
can
set
set
up
up
a
a
GitHub
github
code
code
space
space
in
in
the
the
cloud,
cloud
which
which
will
will
give
give
you
you
the
the
full
full
power
power
of
of
Versus
versus
Code
code
and
and
is
is
likely
likely
much
much
faster
faster
than
than
your
your
grandma's
grandma's
computer.
computer
But
but
now,
now
let's
let's
switch
switch
gears
gears
to
to
one
one
of
of
my
my
favorite
favorite
git
git
commands,
commands
stash.
stash
Have
have
you
you
ever
ever
spent
spent
time
time
working
working
on
on
some
some
changes
changes
that
that
almost
almost
work,
work
but
but
they
they
can't
can't
really
really
be
be
committed
committed
yet
yet
because
because
they
they
break
break
everything
everything
else?
else
Or
or
or
or
maybe
maybe
it's
it's
just
just
really
really
sloppy
sloppy
and
and
you
you
don't
don't
want
want
all
all
your
your
friends
friends
to
to
see
see
it
it
yet.
yet
Git
git
stash
stash
will
will
remove
remove
the
the
changes
changes
from
from
your
your
current
current
working
working
directory
directory
and
and
save
save
them
them
for
for
later
later
use
use
without
without
committing
committing
them
them
to
to
the
the
repo.
repo
The
the
simple
simple
way
way
to
to
use
use
it
it
is
is
git
git
stash
stash
and
and
then
then
git
git
pop
pop
when
when
you're
you're
ready
ready
to
to
add
add
those
those
changes
changes
back
back
into
into
your
your
code.
code
But
but
if
if
you
you
use
use
the
the
command
command
a
a
lot,
lot
you
you
can
can
use
use
git
git
stash
stash
save
save
followed
followed
by
by
a
a
name
name
to
to
reference
reference
it
it
later.
later
Then
then
when
when
you're
you're
ready
ready
to
to
work
work
on
on
it
it
again,
again
use
use
git
git
stash
stash
list
list
to
to
find
find
it,
it
then
then
git
git
stash
stash
apply
apply
with
with
the
the
corresponding
corresponding
index
index
to
to
use
use
it.
it
Now,
now
if
if
you
you
wanna
wanna
use
use
a
a
stash
stash
at
at
grandma's
grandma's
house,
house
you're
you're
pretty
pretty
much
much
s
s
o
o
l,
l
unless
unless
you
you
use
use
a
a
GitHub
github
Codespace,
codespace
in
in
which
which
case,
case
your
your
stashes
stashes
would
would
be
be
saved
saved
in
in
the
the
cloud.
cloud
That's
that's
pretty
pretty
cool,
cool
but
but
now
now
I
i
have
have
a
a
public
public
service
service
announcement
announcement
for
for
developers
developers
in
in
the
the
modern
modern
era.
era
Historically,
historically
the
the
default
default
branch
branch
in
in
git
git
is
is
called
called
the
the
master
master
branch,
branch
but
but
post
post
2020,
2020
this
this
term
term
is
is
no
no
longer
longer
the
the
preferred
preferred
nomenclature.
nomenclature
Refer
refer
to
to
it
it
as
as
main,
main
mega,
mega
or
or
mucho,
mucho
to
to
stay
stay
out
out
of
of
trouble.
trouble
To
to
change
change
it,
it
use
use
git
git
branch
branch
followed
followed
by
by
the
the
m
m
flag
flag
and
and
rename
rename
it
it
to
to
main
main
or
or
maybe
maybe
get
get
creative
creative
and
and
invent
invent
your
your
own
own
name.
name
Now,
now
another
another
command
command
you're
you're
probably
probably
familiar
familiar
with
with
is
is
git
git
log
log
to
to
view
view
a
a
history
history
of
of
commits.
commits
The
the
problem
problem
with
with
this
this
command
command
is
is
that
that
the
the
output
output
is
is
harder
harder
and
and
harder
harder
to
to
read
read
as
as
your
your
project
project
grows
grows
in
in
complexity.
complexity
To
to
make
make
the
the
output
output
more
more
readable,
readable
add
add
the
the
options
options
of
of
graph,
graph
oneline,
oneline
and
and
decorate.
decorate
You
you
can
can
now
now
see
see
a
a
more
more
concise
concise
breakdown
breakdown
and
and
how
how
different
different
branches
branches
connect
connect
together.
together
But
but
if
if
you're
you're
looking
looking
at
at
the
the
Git
git
log,
log
there's
there's
likely
likely
a
a
commit
commit
in
in
there
there
that's
that's
currently
currently
breaking
breaking
your
your
app.
app
Git
git
bisect
bisect
allows
allows
you
you
to
to
start
start
from
from
a
a
commit
commit
that
that
is
is
known
known
to
to
have
have
a
a
bug,
bug
likely
likely
the
the
most
most
recent
recent
commit,
commit
but
but
you
you
knew
knew
that
that
the
the
app
app
was
was
working
working
a
a
few
few
hours
hours
ago.
ago
You
you
can
can
point
point
bisect
bisect
to
to
the
the
last
last
known
known
working
working
commit,
commit
then
then
it
it
performs
performs
a
a
binary
binary
search
search
to
to
walk
walk
you
you
through
through
each
each
commit
commit
in
in
between.
between
If
if
the
the
commit
commit
looks
looks
good,
good
type
type
bisect
bisect
good
good
to
to
move
move
on
on
to
to
the
the
next
next
commit.
commit
Eventually,
eventually
you'll
you'll
find
find
the
the
bad
bad
one
one
and
and
know
know
exactly
exactly
which
which
code
code
needs
needs
to
to
be
be
fixed.
fixed
Another
another
their
their
advanced
advanced
Git
git
technique
technique
that
that
every
every
developer
developer
should
should
know
know
is
is
how
how
to
to
squash
squash
their
their
commits.
commits
Imagine
imagine
you're
you're
working
working
on
on
a
a
feature
feature
branch
branch
that
that
has
has
3
3
different
different
commits,
commits
and
and
you're
you're
ready
ready
to
to
merge
merge
it
it
into
into
the
the
master
master
branch,
branch
I
i
mean
mean
main
main
branch.
branch
But
but
all
all
these
these
commit
commit
messages
messages
are
are
kind
kind
of
of
pointless
pointless
and
and
it
it
would
would
be
be
better
better
if
if
it
it
was
was
just
just
one
one
single
single
commit.
commit
We
we
can
can
do
do
that
that
from
from
our
our
feature
feature
branch
branch
by
by
running
running
git
git
rebase
rebase
with
with
the
the
interactive
interactive
option
option
for
for
the
the
main
main
branch.
branch
That'll
that'll
pull
pull
up
up
a
a
file
file
with
with
a
a
list
list
of
of
commits
commits
on
on
this
this
branch.
branch
If
if
we
we
want
want
to
to
use
use
a
a
commit,
commit
we
we
just
just
use
use
that
that
pick
pick
command.
command
We
we
can
can
also
also
change
change
a
a
message
message
using
using
the
the
reword
reword
command,
command
or
or
we
we
can
can
combine
combine
or
or
squash
squash
everything
everything
into
into
that
that
original
original
commit
commit
using
using
and
and
squash,
squash
go
go
ahead
ahead
and
and
save
save
the
the
file
file
and
and
close
close
it.
it
Git
git
will
will
pull
pull
up
up
another
another
file,
file
prompting
prompting
you
you
to
to
update
update
the
the
commit
commit
message,
message
which
which
by
by
default
default
will
will
be
be
a
a
combination
combination
of
of
all
all
the
the
messages
messages
that
that
you
you
just
just
squash.
squash
And
and
if
if
you
you
don't
don't
like
like
all
all
the
the
messages
messages
to
to
be
be
combined,
combined
you
you
can
can
use
use
fixup
fixup
instead
instead
of
of
squash
squash
when
when
doing
doing
the
the
rebase.
rebase
To
to
be
be
even
even
more
more
productive,
productive
you
you
can
can
also
also
use
use
fixup
fixup
and
and
squash
squash
flags
flags
when
when
making
making
commits
commits
on
on
your
your
branch.
branch
When
when
you
you
do
do
that,
that
it
it
tells
tells
git
git
in
in
advance
advance
that
that
you
you
want
want
to
to
squash
squash
them.
them
So
so
when
when
you
you
go
go
to
to
do
do
a
a
rebase
rebase
with
with
the
the
auto
auto
squash
squash
flag,
flag
it
it
can
can
handle
handle
all
all
the
the
squashing
squashing
automatically.
automatically
Now,
now
if
if
you
you
maintain
maintain
a
a
repo,
repo
one
one
tool
tool
that
that
can
can
be
be
very
very
useful
useful
is
is
git
git
hooks.
hooks
Whenever
whenever
you
you
perform
perform
an
an
operation
operation
with
with
git,
git
like
like
a
a
commit
commit
for
for
example,
example
well,
well
it
it
creates
creates
an
an
event
event
and
and
hooks
hooks
allow
allow
you
you
to
to
run
run
some
some
code
code
either
either
before
before
or
or
after
after
that
that
event
event
happens.
happens
If
if
you
you
look
look
in
in
the
the
hidden
hidden
git
git
directory,
directory
you'll
you'll
see
see
a
a
directory
directory
there
there
called
called
hooks.
hooks
And
and
inside
inside
of
of
it,
it
you'll
you'll
find
find
a
a
bunch
bunch
of
of
different
different
scripts
scripts
that
that
can
can
be
be
configured
configured
to
to
run
run
when
when
different
different
events
events
in
in
it
it
happened.
happened
If
if
you
you
happen
happen
to
to
be
be
a
a
JavaScript
javascript
developer,
developer
there's
there's
a
a
package
package
called
called
Husky
husky
that
that
makes
makes
it
it
much
much
easier
easier
to
to
configure
configure
Git
git
Hooks.
hooks
For
for
example,
example
you
you
you
you
might
might
install
install
it
it
with
with
npm,
npm
then
then
create
create
a
a
script
script
that
that
will
will
validate
validate
or
or
link
link
your
your
code
code
before
before
each
each
commit,
commit
and
and
that
that
can
can
help
help
improve
improve
your
your
overall
overall
code
code
quality.
quality
To
to
wrap
wrap
things
things
up,
up
let's
let's
talk
talk
about
about
deleting
deleting
things.
things
Let's
let's
imagine
imagine
you
you
have
have
a
a
remote
remote
repository
repository
on
on
GitHub,
github
then
then
a
a
local
local
version
version
on
on
your
your
machine
machine
that
that
you've
you've
been
been
making
making
changes
changes
to,
to
but
but
things
things
haven't
haven't
been
been
going
going
well,
well
and
and
you
you
just
just
want
want
to
to
go
go
back
back
to
to
the
the
original
original
state
state
in
in
the
the
remote
remote
repo.
repo
1st,
1st
do
do
a
a
git
git
fetch
fetch
to
to
grab
grab
the
the
latest
latest
code
code
in
in
the
the
remote
remote
repo.
repo
Then,
then
use
use
reset
reset
with
with
the
the
hard
hard
flag
flag
to
to
override
override
your
your
local
local
code
code
with
with
the
the
remote
remote
code.
code
But
but
be
be
careful,
careful
your
your
local
local
changes
changes
will
will
be
be
lost
lost
forever.
forever
But
but
you
you
might
might
still
still
be
be
left
left
with
with
some
some
random
random
untracked
untracked
files,
files
or
or
build
build
artifacts
artifacts
here
here
and
and
there.
there
Use
use
the
the
git
git
clean
clean
command
command
to
to
remove
remove
those
those
files
files
as
as
well.
well
But
but
if
if
you're
you're
sick
sick
of
of
git
git
at
at
this
this
point
point
and
and
want
want
to
to
just
just
get
get
rid
rid
of
of
it
it
altogether,
altogether
maybe
maybe
you
you
wanna
wanna
try
try
out
out
Apache
apache
Subversion
subversion
to
to
change
change
things
things
up
up
a
a
bit.
bit
All
all
you
you
have
have
to
to
do
do
is
is
delete
delete
that
that
hidden
hidden
git
git
folder
folder
and
and
you're
you're
on
on
your
your
own
own
again.
again
Oh,
oh
and
and
there's
there's
one
one
other
other
tip
tip
I
i
almost
almost
forgot
forgot
about
about
that
that
comes
comes
in
in
really
really
handy.
handy
If
if
you
you
recently
recently
switched
switched
out
out
of
of
a
a
branch
branch
and
and
forgot
forgot
its
its
name,
name
you
you
can
can
use
use
git
git
checkout
checkout
followed
followed
by
by
a
a
dash
dash
to
to
go
go
directly
directly
back
back
into
into
the
the
previous
previous
branch
branch
that
that
you
you
were
were
working
working
on.
on
I'm
i'm
gonna
gonna
go
go
ahead
ahead
and
and
wrap
wrap
things
things
up
up
there.
there
If
if
you
you
have
have
any
any
additional
additional
Git
git
tips,
tips
make
make
sure
sure
to
to
leave
leave
them
them
in
in
the
the
comments.
comments
And
and
if
if
you
you
want
want
to
to
master
master
demos
demos
of
of
Git
git
step
step
by
by
step,
step
check
check
out
out
the
the
full
full
course
course
on
on
FireShip
fireship
IO.
io
Thanks
thanks
for
for
watching,
watching
and
and
I
i
will
will
see
see
you
you
in
in
the
the
next
next
one.
one
success
The importance of submitting a pull request and learning about Git through a course on Fireship IO is emphasized, along with advice on becoming a professional Git user quickly. A course on Fireship IO provides short videos and exercises to transform a professional Git user quickly, including a course on Fireship IO for a modern learning path. Different developers use various Git command, including git push, git revert, and git stash, and provide examples and instructions for each command, including the use of the options for the master branch and the option for fixing the message when combining files. The course provides tips on how to delete unwanted code and remove unnecessary files, and viewers are encouraged to leave their questions in the comments and to check out the full course on Firehair IO.
13 Advanced (but useful) Git Techniques and Shortcuts
One of the best pieces of advice I ever got was git 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 and 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 and tips and tricks to make you more productive with Git. But if you're new to Git, I just released a short course on 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 wanna 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 add 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 way to get the job done. You can get rid of the git add and go straight to commit by using the a m 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, this is, which are commonly used to shorten existing commands or create your own new custom commands. For example, we might create an alias called a c e, 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 we'll lose them forever. And your coworkers 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 version. I made your trouble. 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 wanna work on, then hit the period key on your keyboard. And like magic, it pulls up a browser based version of Versus 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 Versus 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 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 git stash and then git 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 wanna use a stash at grandma's house, you're pretty much s o l, unless you use a GitHub Codespace, 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 git 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, oneline, 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. Git 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 their advanced Git technique that every developer should know is how to squash their commits. Imagine you're working on a feature branch that has 3 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 that pick command. We can also change a message using the reword command, or we can combine or squash everything into that original commit using and 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 squash. And if you don't like all the messages to be combined, you can use fixup instead of squash when doing the rebase. To be even more productive, you can also use fixup 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 git hooks. Whenever you perform an operation with git, like a commit for example, well, 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 it happened. 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 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, then a local version on your machine that you've been making changes to, but things haven't been going well, and you just want to go back to the original state in the remote repo. 1st, 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 git clean command to remove those files as well. But if you're sick of git at this point and want to just get rid of it altogether, maybe you wanna 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 gonna 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 demos of Git step by step, check out the full course on FireShip IO. Thanks for watching, and I will see you in the next one.
The importance of submitting a pull request and learning about Git through a course on Fireship IO is emphasized, along with advice on becoming a professional Git user quickly. A course on Fireship IO provides short videos and exercises to transform a professional Git user quickly, including a course on Fireship IO for a modern learning path. Different developers use various Git command, including git push, git revert, and git stash, and provide examples and instructions for each command, including the use of the options for the master branch and the option for fixing the message when combining files. The course provides tips on how to delete unwanted code and remove unnecessary files, and viewers are encouraged to leave their questions in the comments and to check out the full course on Firehair IO.