Git is a fantastic distributed version control system that is used by millions of developers around the world. It is a powerful tool that allows you to track changes in your codebase, collaborate with other developers, and manage your codebase effectively. In this article, I will share some of the most useful git commands that I use on a daily basis.
Track file and folder case changes
By default, git treats folder and file names as case insensitive so if you rename something from App.tsx to app.tsx then git does not detect any changes, unfortunately typescript imports are case sensitive and it would cause an error in the app. disabling ignore case would allow git to properly rename the file or folder to be used by the rest of the team
git config --global core.ignorecase falseUndo a commit
Undo the last commit and keep the changes in the working directory
git reset --soft HEAD~1Disable showing branches in VIM
Disable showing branches in VIM when you run git branch -a or git branch -r by running the following command
git config --global pager.branch falseAmend a commit
Best used when you want to add more changes to the last commit without creating a new commit. I often use this when I forget to add a file to the last commit. Caveat: this will change the commit hash so be careful when using it on a commit that has been pushed to the remote repository. If you already pushed the commit to the remote repository then you will need to force push the changes to the remote repository using git push -f
git commit --amend --no-editPrune branches
Pruning branches will remove any branches that have been deleted from the remote repository. This is useful when you have a lot of branches in your local repository and you want to clean them up.
git remote update origin --pruneI typically create an alias for this command to make it easier to run by adding the following line to my .bashrc or .zshrc file
alias gprune="git remote update origin --prune"Delete remotely deleted branches
This command will delete all branches that have been deleted from the remote repository. This is useful when you have a lot of branches in your local repository and you want to clean them up.
git branch | egrep -v \"(^\*|main|dev)\" | xargs git branch -DI typically create an alias for this command to make it easier to run by adding the following line to my .bashrc or .zshrc file
alias gclean="git branch | egrep -v \"(^\*|main|dev)\" | xargs git branch -D"Conclusion
Written by

Guy Shahine
Founder / CEO
guyshahine.comGuy is a software engineer with over 20 years of experience in building video games, web, mobile and cloud applications. He has a passion for creating high-quality software solutions that are scalable, reliable, and user-friendly. Guy is also an advocate for agile methodologies and best practices in software development.
View profile →
