git add -p # Add changes interactivelygit branch -avv # Show all branchesgit clean -fd # Remove untracked filesgit diff branch1..branch2 # Show the difference between two branchesgit log --author="author" # Show commits by authorgit log --follow -- path/to/file # Show commits for a filegit reset --soft HEAD~1 # Uncommit the last commit
🔄 Creating aliases
git config --global alias.co checkout # git cogit config --global alias.st 'status -s' # git stgit config --global alias.fm "!git fetch && git merge" # git fm# Add all changes and commit with a message# Usage: git ac "message"git config --global alias.ac '!git add -A && git commit -m'# Amend the last commit without changing the commit message# Usage: git amendgit config --global alias.amend 'commit --amend --no-edit'
❌ Global gitignore
# Global gitignore for all repositoriesgit config --global core.excludesfile ~/.gitignore_global# Example entries for .gitignore_globalecho ".DS_Store" >> ~/.gitignore_globalecho "node_modules/" >> ~/.gitignore_globalecho "env/" >> ~/.gitignore_global
📅 Set the date of the last commit to the current date
git format-patch -5 # Create patches for the last 5 commitsgit format-patch -n HEAD~5..HEAD -o /path/to/output # Create patches for the last 5 commits and save them to a specific directorygit format-patch -n <commit_hash> # Create a patch for a specific commitgit am *.patch # Apply patchesgit send-email *.patch # Send patches via email