Advanced Git Commands for Pro Developers
Posted on June 7, 2024 • 2 min read • 280 wordsEnhance your Git skills with advanced commands that boost productivity and streamline your development workflow.
For more experienced developers, advanced Git commands can significantly enhance productivity and workflow. Here are some advanced commands to take your Git skills to the next level:
git rebase -i HEAD~nAllows you to edit commit history, reorder, squash, or combine commits. This helps maintain a clean and coherent commit history.
git cherry-pick commit-hashApplies changes from specific commits to your current branch. Useful for selectively applying changes.
git rebase -i HEAD~nCombines multiple commits into one, making your project history cleaner and more understandable.
git bisect start
git bisect bad
git bisect good commit-hashUses binary search to find the commit that introduced a bug. This is a powerful debugging tool.
git stash
git stash applyTemporarily saves changes that are not yet ready to be committed, allowing you to switch branches or work on something else.
# Example: Pre-commit hook
echo "npm test" > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commitAutomates tasks with Git hooks, such as running tests before a commit or checking code quality.
git branch -u origin/branch-nameSets up tracking information for a branch, ensuring that your local branch is synchronized with the remote
branch.
git clean -fRemoves untracked files from the working directory, keeping your project clean and organized.
git blame filenameShows what revision and author last modified each line of a file. Useful for tracking down the origin of changes.
git reflogShows a log of all the references in the repository, allowing you to recover from mistakes or changes in the branch history.