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~n
Allows you to edit commit history, reorder, squash, or combine commits. This helps maintain a clean and coherent commit history.
git cherry-pick commit-hash
Applies changes from specific commits to your current branch. Useful for selectively applying changes.
git rebase -i HEAD~n
Combines multiple commits into one, making your project history cleaner and more understandable.
git bisect start
git bisect bad
git bisect good commit-hash
Uses binary search to find the commit that introduced a bug. This is a powerful debugging tool.
git stash
git stash apply
Temporarily 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-commit
Automates tasks with Git hooks, such as running tests before a commit or checking code quality.
git branch -u origin/branch-name
Sets up tracking information for a branch, ensuring that your local branch is synchronized with the remote
branch.
git clean -f
Removes untracked files from the working directory, keeping your project clean and organized.
git blame filename
Shows what revision and author last modified each line of a file. Useful for tracking down the origin of changes.
git reflog
Shows a log of all the references in the repository, allowing you to recover from mistakes or changes in the branch history.