Tech talks: Git basics
A summary of the first Instea tech talk session covering Git fundamentals: merge vs rebase, stash, git fetch, log visualization, and aliases.
The Instea team established an educational program featuring hour-long sessions where employees discuss best practices and emerging technologies. This post summarizes the first session focused on Git fundamentals.
Merge vs Rebase
git pull by default merges changes, creating a non-linear history with multiple merge commits. An alternative approach using git pull --rebase replays local work over the latest codebase, maintaining a linear history.
The tradeoff: conflicts during rebase make the original commit unavailable for review.
# Default merge approach
git pull
# Rebase approach (linear history)
git pull --rebaseStash
This feature allows developers to temporarily set aside uncommitted work:
# Save uncommitted changes
git stash
# Restore saved changes
git stash popAdditional Tips
Use git fetch to download remote changes without affecting local work:
git fetchFor better visualization of all branches:
git log --all
gitk --allCreate custom git aliases for frequently-used commands. Example alias for enhanced log formatting with color and graph visualization:
# Add to ~/.gitconfig
[alias]
lg = log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit