Advanced Git Concepts

advanced30 min

Advanced commands

These tools fix mistakes, pause work, or tidy history. Use them on branches you own or after the team agrees on policy.

Undoing commits

git reset --soft HEAD~1    # Undo commit, keep changes staged
git reset --mixed HEAD~1   # Undo commit, unstage changes
git reset --hard HEAD~1     # Undo commit, discard all changes
git revert HEAD            # New commit that undoes previous
git checkout -- filename   # Discard changes in working directory

reset --hard deletes uncommitted work on those commits. On shared branches, prefer revert so history stays safe for everyone.

Stash

Save uncommitted work without committing:

git stash
git stash pop
git stash list

Useful when you need to pull but are not ready to commit.

Rebase

git rebase replays your commits on top of another branch for a linear history. git rebase -i can squash or reorder commits. Do not rebase commits others already pulled unless the team uses that workflow.

Tags

Mark releases or event-ready code:

git tag -a v1.0 -m "Competition ready"

Push tags with git push --tags. GitHub Releases can attach notes and artifacts.

Further Reading Resources