5 Git Shortcuts to Improve Your Coding Speed and Efficiency
Simplify your Git workflow and speed up your coding with these 5 essential Git shortcuts. Learn how to work smarter, not harder, in your programming.
In the past two years of my coding career, I’ve seen more job offers for developers than any other role. Companies look for any kind of programmer able to create software, and this hunt for geeks is varied, ranging from Web developers to Dev Ops, from iOS and Android engineers to hybrid app developers. Something common to nearly every role was always a required skill: being able to work with Git.
It sounds pretty normal, Git is an essential tool to keep track of the progress and evolution of any software project. The documentation online is really good, and every beginner knows it is important to get at least a basic knowledge of this tool to have a chance to get one of those developer positions.
Today I won’t show you the well-known, basic commands, but I’ll give you some additional tricks that I found useful to increase my productivity when working with Git and get the most out of it.
Command 1: Formatted logging
It is a combination of options available for the git log
command which will make your commit history more user-friendly and easy to interact with. For example, it pipes searches with grep or other bash commands.
The options from the help page of the command:
- pretty: It allows the user to format the log using many placeholders. You can find the entire list of them at Git pretty formats.
- graph: Draw a text-based graphical representation of the commit history on the left-hand side of the output.
- all: Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as commit.
This is a long command, so create an alias on your terminal to make your life easier 😅
Command 2: Remove merged branches
This is probably one of the aliases I use the most. It takes care of removing all the merged branches, keeping clean your local repository from legacy branches and saving the time of deleting manually each one of them.
I saved it as a clear
alias since it removes stuff from the repo.
clear = "!git branch — merged | grep -v ‘*’ | xargs -n 1 git branch -d"
Command 3: Add files to a previous commit
How often do you commit forgetting to add a file to the stage before doing it? Ouch! This is pretty common even for people with a strong workflow, and resetting that commit to creating a new one including the missing files is not the fastest solution. With this command, you can edit your last commit adding files quickly and safely:
Easy right? Pretty fast and clean! commend
is the alias created for this command:
Command 4: Track your commits
Have you ever wanted to check all the commits you made since a specific time in a repo? It could be helpful to keep track of your performance and see how you’re performing as your skills grow! This command will show you your commits in a repo since a time you can pass as an argument to the alias we’ll create now. I also combine it with the git ls
I showed you before:
Why does this look different from a normal alias? Because we need to use a shell to interpolate the argument for the time value. The result is pretty wonderful🚀
Command 5: Create a .zip of your repo
If you need to export an archive of your current HEAD revision, and you want to avoid including node_modules
and all the other .gitignore
files, this is the command for you! It creates a zip archive of the files with the name you pass at the end of the alias:
Doing so, with a simple git export myRepo
, you’ll create your copy in just a second!
Summary
Proper usage of git will drastically increase your productivity and help you to work better in a team! It is an amazing tool that keeps evolving. I recommend following the changelog of future releases to stay updated about the latest features!
Last updated: