15 September 2023
You've learned the basics on our Git for Beginners course- initialising repositories, making commits, creating branches, pushing to remote, and collaborating on GitHub. Now it's time to unlock more advanced Git capabilities to level up your version control skills.
This guide explores intermediate to advanced Git techniques for maximizing productivity. Follow along to master branching strategies, resetting commits, advanced collaboration, and other skills to boost your Git proficiency.
Branching unlocks parallel workflows in Git. Here are some best practices for an effective branching strategy:
git branch --merged | grep -v \* | xargs git branch -d
Git rebase lets you reorder, squash, edit, or modify existing commits. For example:
# Interactive rebase git rebase -i HEAD~5 # Squash last 2 commits git rebase -i HEAD~2 # Reorder commits git rebase -i HEAD~5
This helps clean up local history before sharing branches. Use with caution - don't rebase public commits.
git reset
erases commits, moving the branch tip backwards. git revert
preserves commit history by adding a new commit that reverts changes:
# Undo last commit, keep changes git reset HEAD~1 # Discard changes from last commit git reset --hard HEAD~1 # Create new commit undoing changes git revert HEAD~1
In most cases, prefer revert over reset to avoid losing data or rewriting public history.
Cherry picking lets you selectively apply commits from one branch to another:
# Apply commit <commit-hash> onto current branch git cherry-pick <commit-hash> # Cherry pick multiple commits git cherry-pick <commit-1> <commit-2>
This is useful for moving specific changes between branches.
Remotes connect your local repository with shared counterparts like GitHub:
# Add remote repo git remote add <name> <url> # Fetch latest changes git fetch <remote> # Merge remote branch git merge <remote>/<branch> # Rebase on top of remote git rebase <remote>/<branch>
Use git remote -v
to list configured remotes. origin
refers to the default remote.
With these intermediate skills, you can achieve efficient parallel development, undo mistakes, integrate work and share repositories.
For more advanced techniques, explore Git hooks, submodules, rebasing vs. merging, Git blame and bisect, logging, stash, patches and more.
The official Git docs are a fantastic resource for leveling up Git mastery. Keep learning - there's always more to uncover with Git!
Our previous article is Git and GitHub for Beginners: A Step-by-Step Guide or check out our article Learn Git and GitHub with these 10 Essential Commands or you might like to take one of our courses in Git and Github
CONTACT
+44 (0)20 8446 7555
Copyright © 2023 JBI Training. All Rights Reserved.
JB International Training Ltd - Company Registration Number: 08458005
Registered Address: Wohl Enterprise Hub, 2B Redbourne Avenue, London, N3 2BS
Modern Slavery Statement & Corporate Policies | Terms & Conditions | Contact Us