© Gennaro Nucaro 2026 | All Rights Reserved
# Set global username
git config --global user.name "Your Name"
# Set global email
git config --global user.email "your.email@example.com"
# Verify global configuration
git config --list
# Set local username (only for the current repository)
git config user.name "Your Name"
# Set local email (only for the current repository)
git config user.email "your.email@example.com"
# Verify local configuration
git config --local --list# Initialize a new Git repository
git init
# Clone an existing repository
git clone <repository-url># Add files to the staging area
git add <file>
# Add all modified files to the staging area
git add .
# Remove files from the staging area
git reset <file>
# Check the repository status
git status
# Show differences for modified files
git diff# Commit files in the staging area
git commit -m "Commit message"
# Commit changes bypassing the staging area
git commit -a -m "Commit message"# Create a new branch
git branch <branch-name>
# Switch to an existing branch
git checkout <branch-name>
# Create and switch to a new branch
git checkout -b <branch-name>
# Delete a branch
git branch -d <branch-name># Merge a branch into the current branch
git merge <branch-name>
# Resolving merge conflicts
# (Edit the conflicted files and then)
git add <conflicted-file>
git commit -m "Resolved merge conflict"# Add a remote repository
git remote add origin <repository-url>
# View remote repositories
git remote -v
# Fetch changes from the remote repository
git fetch
# Merge changes from the remote repository
git pull
# Push changes to the remote repository
git push origin <branch-name># Save uncommitted changes
git stash
# View the stash list
git stash list
# Retrieve changes from the latest stash
git stash apply
# Retrieve changes from a specific stash
git stash apply stash@{2}
# Retrieve changes and remove the stash
git stash pop# Show the reference log
git reflog
# Recover a specific commit from reflog
git checkout <commit-id># Start a bisect session
git bisect start
# Mark a "bad" commit (where the bug is present)
git bisect bad <commit-id>
# Mark a "good" commit (where the bug is not present)
git bisect good <commit-id>
# Continue the process with tests until Git finds the problematic commit
git bisect run <test-script># Apply a specific commit to the current branch
git cherry-pick <commit-id># Generate a condensed log
git shortlog
# Generate a condensed log sorted by number of commits per author
git shortlog -n -s# Show who modified each line of a file
git blame <file># Search for a specific word or phrase in the repository
git grep "keyword"
# Search for a specific word or phrase in commits
git log -S "keyword"# Show the commit log
git log
# Show a simplified log with branch graphs
git log --oneline --graph --all
# Reset the current branch to the latest commit
git reset --hard
# Restore a specific file to the latest commit
git checkout -- <file>
# Create a tag
git tag <tag-name>
# Delete a tag
git tag -d <tag-name>© Gennaro Nucaro 2026 | All Rights Reserved