Module Overview
What You'll Learn
- Use tags and releases
- Create Git aliases
- Work with Git hooks
- Advanced workflows
Time Estimate
35-50 minutes
Prerequisites
Module 4: Remote Repositories & Collaboration
Tags and Releases
Creating Tags
Mark important points in your repository history:
git tag v1.0.0
Create a lightweight tag
git tag -a v1.0.0 -m "Version 1.0.0 release"
Create an annotated tag with message
Managing Tags
List and manage your tags:
git tag
List all tags
git push origin v1.0.0
Push a specific tag to remote
git push origin --tags
Push all tags to remote
GitHub Releases
Creating a Release:
- 1. Create and push a tag to GitHub
- 2. Go to your repository on GitHub
- 3. Click "Releases" in the right sidebar
- 4. Click "Create a new release"
- 5. Select your tag and add release notes
- 6. Upload any release assets (binaries, etc.)
Git Aliases
Creating Aliases
Create shortcuts for commonly used commands:
git config --global alias.st status
Create alias 'st' for 'status'
git config --global alias.co checkout
Create alias 'co' for 'checkout'
git config --global alias.br branch
Create alias 'br' for 'branch'
Advanced Aliases
Create more complex aliases with multiple commands:
git config --global alias.lg "log --oneline --graph --all"
Create a pretty log alias
git config --global alias.unstage "reset HEAD --"
Create alias to unstage files
Using Aliases
Use your new aliases:
git st
Use 'st' alias for status
git lg
Use 'lg' alias for pretty log
Git Hooks
Understanding Hooks
Git hooks are scripts that run automatically at certain points in Git's workflow:
Common Hook Types:
- • pre-commit: Runs before a commit is created
- • post-commit: Runs after a commit is created
- • pre-push: Runs before pushing to remote
- • post-merge: Runs after a merge is completed
Creating a Pre-commit Hook
Create a hook to run tests before committing:
touch .git/hooks/pre-commit
Create the pre-commit hook file
chmod +x .git/hooks/pre-commit
Make the hook executable
Example Pre-commit Hook
A simple hook to check for TODO comments:
#!/bin/sh # Check for TODO comments in staged files if git diff --cached --name-only | xargs grep -l "TODO"; then echo "Error: TODO comments found in staged files" echo "Please remove TODO comments before committing" exit 1 fi exit 0
Advanced Workflows
Git Flow
A branching model for managing releases:
Branch Structure:
- • main: Production-ready code
- • develop: Integration branch for features
- • feature/*: Individual feature branches
- • release/*: Release preparation branches
- • hotfix/*: Emergency fixes for production
GitHub Flow
A simpler workflow for continuous deployment:
Workflow Steps:
- 1. Create a branch from main
- 2. Make changes and commit them
- 3. Push the branch to GitHub
- 4. Create a Pull Request
- 5. Review and discuss changes
- 6. Merge to main and deploy
Rebase Workflow
Keep your commit history clean with rebasing:
git rebase main
Rebase your branch onto main
git rebase -i HEAD~3
Interactive rebase to squash commits
Cherry-picking
Apply specific commits to different branches:
git cherry-pick abc1234
Apply a specific commit to current branch
Module Quiz
Test your understanding of advanced Git features.