0% found this document useful (0 votes)
7 views3 pages

Git Commands Reference

This document provides a quick reference guide for common Git commands, organized into categories such as setup, basic workflow, branching, remote repositories, and more. It includes commands for viewing history, undoing changes, stashing, tagging, and advanced operations, along with useful flags and common workflows. Additionally, it offers helpful aliases for frequently used commands to streamline the Git experience.

Uploaded by

PaleWalker47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Git Commands Reference

This document provides a quick reference guide for common Git commands, organized into categories such as setup, basic workflow, branching, remote repositories, and more. It includes commands for viewing history, undoing changes, stashing, tagging, and advanced operations, along with useful flags and common workflows. Additionally, it offers helpful aliases for frequently used commands to streamline the Git experience.

Uploaded by

PaleWalker47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

GIT COMMANDS QUICK REFERENCE

===========================

=== SETUP & CONFIG ===


git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git config --list # View all settings
git init # Initialize new repository
git clone <url> # Clone remote repository

=== BASIC WORKFLOW ===


git status # Check repository status
git add <file> # Stage specific file
git add . # Stage all changes
git add -A # Stage all changes (including deletions)
git commit -m "message" # Commit with message
git push # Push to remote repository
git pull # Pull latest changes

=== BRANCHING ===


git branch # List all branches
git branch <name> # Create new branch
git checkout <branch> # Switch to branch
git checkout -b <name> # Create and switch to branch
git merge <branch> # Merge branch into current
git branch -d <name> # Delete branch (safe)
git branch -D <name> # Force delete branch

=== REMOTE REPOSITORIES ===


git remote -v # List remotes
git remote add origin <url> # Add remote origin
git remote remove <name> # Remove remote
git push -u origin <branch> # Push and set upstream
git fetch # Download objects from remote
git pull origin <branch> # Pull specific branch

=== VIEWING HISTORY ===


git log # View commit history
git log --oneline # Compact log format
git log --graph # Show branch graph
git show <commit> # Show commit details
git diff # Show unstaged changes
git diff --staged # Show staged changes
git diff <commit1> <commit2> # Compare commits

=== UNDOING CHANGES ===


git checkout -- <file> # Discard changes in file
git reset <file> # Unstage file
git reset --soft HEAD~1 # Undo last commit (keep changes)
git reset --hard HEAD~1 # Undo last commit (discard changes)
git revert <commit> # Create new commit that undoes changes
git clean -f # Remove untracked files
git clean -fd # Remove untracked files and directories

=== STASHING ===


git stash # Stash current changes
git stash pop # Apply and remove latest stash
git stash list # List all stashes
git stash apply stash@{0} # Apply specific stash
git stash drop stash@{0} # Delete specific stash
git stash clear # Delete all stashes

=== TAGGING ===


git tag # List all tags
git tag <tagname> # Create lightweight tag
git tag -a <tagname> -m "message" # Create annotated tag
git push origin <tagname> # Push tag to remote
git push origin --tags # Push all tags

=== ADVANCED OPERATIONS ===


git rebase <branch> # Rebase current branch
git rebase -i HEAD~3 # Interactive rebase (last 3 commits)
git cherry-pick <commit> # Apply specific commit
git bisect start # Start binary search for bugs
git blame <file> # Show who changed each line
git reflog # Show reference log

=== USEFUL FLAGS ===


-v, --verbose # More detailed output
-q, --quiet # Suppress output
--dry-run # Show what would happen
-f, --force # Force operation
-u, --set-upstream # Set tracking branch

=== GITIGNORE PATTERNS ===


*.log # Ignore all .log files
/temp # Ignore temp directory in root
build/ # Ignore build directory anywhere
!important.log # Don't ignore this specific file
*.tmp # Ignore all .tmp files
node_modules/ # Common: ignore Node.js modules
.env # Ignore environment files
*.pyc # Ignore Python compiled files

=== COMMON WORKFLOWS ===


# Start new feature
git checkout -b feature/new-feature
git add .
git commit -m "Add new feature"
git push -u origin feature/new-feature

# Merge feature branch


git checkout main
git pull origin main
git merge feature/new-feature
git push origin main
git branch -d feature/new-feature

# Fix merge conflicts


git status # See conflicted files
# Edit files to resolve conflicts
git add <resolved-files>
git commit -m "Resolve merge conflicts"

=== HELPFUL ALIASES ===


git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'

You might also like