5 Git Tips & Tricks - Git Advices You Need to Know
In this video I will share with you my 5 most important tips and tricks that I learned during last 10 years of working with Git. Also make sure that you want this video until the end because I will share my bonus advices about what you shouldn't do in git. So let's jump right into it.
Use console git
My first tip advice is to invest your time and learn how to use Git from console. There are several reasons for that.
First of all it's a native way to use Git which works in any operational system. This means that you directly see that is going on and what you did. When you click 1 button in some program you have no clue what is happening under the hood.
Also you can start with basic 5-10 commands and learn more commands later. This is completely fine.
Console git is more configurable, you can write own configs for projects and aliases for commands and much more.
I also have a full course on how to use Git from console so if you are interested I will link in down in the description box below.
Invest time in configuring global gitconfig
Git can be configured per project and globally for the whole machine. You can fine config file in .git folder in you project where you have git or globally in your home directory.
There is quite a lot of stuff in gitconfig and it makes sense to spend some time and adjust it for your needs. You can configure there your name, aliases for git, what editor you will use for merges and commits, what merge strategy you prefer and much more. You shouldn't configure it all at once but you can look there from time to time and improve some things.
Learn git workflows like git flow or github flow
My next point is about learning different flows to work with Git. One thing is to learn and understand Git commands but the other thing is to understand how teams are using Git effectively to develop a product from start to the end. 2 most popular flows are Gitflow and Github flow. The goal is that you understand the process where development is happening, how you make features, how you make release of the next version of your product of how you make hotfix if there is a bug on production. This is extremely valuable knowledge while working with Git.
Git diff so fancy
If you are working with Git inside console you probably want to make you diffs and merge conflicts more colorful. This can be easily done with diff-so-fancy plugin. As you can see it highlight diff much better so we can understand what was changed easier.
Configure Git aliases
My next point is about configuring aliases. When you use Git from terminal you can create your own aliases to simplify working with Git any type commands faster.
For example I can write gaa to add all untracked files to git, gc "message" to commit my changes and gp to push them to remote. All this you can configure with global git config and your terminal. And actually I made a full video on how to create aliases in Git so in case you missed it I will link it in the description.
Bonus - Don't do this
And here is my bonus that I promised. Here are 5 more point about what you should stop doing with Git to avoid problems and complications.
- don't remote .git folder. There all Git history and revisions are stored. Removing it means removing Git from your project completely. You never want this.
- don't push with force. It's extremely easy to break your whole history if something goes wrong. And I'm not only talking here about pushing with force to master but to any branch. Just never do it. Also I highly recommend to make your master and develop branches protected in order to disallow force push.
- don't push build files and node_modules in repository. It blows the files amount of your repository and doesn't make any sense. Any developer can download libraries using lock files and generate build files again. You must put things like build folders or node_modules in gitignore file.
- Always make copy of branch if you do something that you are not sure or difficult. Just create a new branch from the branch that you maybe can corrupt to be on the safe side. You can always just remove corrupted branch and rename branch from backup later.
- don't use rebases and just use merges if you don't want complications. I made a full video on this topic so if you are interested check it out. The simple answer forget that rebase exists.
So here were my tips and tricks to work with Git. And what are yours? Write me down in the comments below.
Want to conquer your next JavaScript interview? Download my FREE PDF - Pass Your JS Interview with Confidence and start preparing for success today!