Checkout to main branch and pull latest changes. Use when starting a new task or work session.
Checkout to main branch and pull latest changes from remote. Perfect for starting a fresh task or work session.
Check if current directory is a git repository:
git rev-parse --git-dir > /dev/null 2>&1
If not, inform the user: "Not a git repository. Cannot proceed."
Get current branch name:
git branch --show-current
Check for uncommitted changes:
git status --porcelain
If there are uncommitted changes, ask the user:
You have uncommitted changes. Options:
1. Stash changes (git stash)
2. Discard changes (git reset --hard)
3. Cancel and handle manually
Which option? (1/2/3)
Checkout to main branch (try common names):
git checkout main 2>/dev/null || git checkout master 2>/dev/null || git checkout dev 2>/dev/null || {
echo "No main/master/dev branch found. Available branches:"
git branch -a
exit 1
}
Pull latest changes:
git pull origin $(git branch --show-current)
Show summary:
echo "✓ Now on $(git branch --show-current)"
echo "✓ Latest changes pulled"
echo ""
git log -1 --oneline
echo ""
echo "Ready for a fresh start! 🚀"
git stash pop to restore."