# Git Cheatsheet This is a quick reference for common Git commands. ## Configuration - `git config --global user.name "Your Name"`: Set your username - `git config --global user.email "your.email@example.com"`: Set your email - `git config --list`: View configuration ## Creating Repositories - `git init`: Initialize a new Git repository in the current directory - `git clone `: Clone an existing repository ## Basic Snapshotting - `git status`: Show the working tree status - `git add `: Add a file to the staging area - `git add .`: Add all changes in the current directory to the staging area - `git commit -m "commit message"`: Commit staged changes with a message - `git commit -a -m "commit message"`: Commit all tracked changes with a message (skips staging) ## Branching and Merging - `git branch`: List all branches - `git branch `: Create a new branch - `git checkout `: Switch to a branch - `git checkout -b `: Create and switch to a new branch - `git merge `: Merge a branch into the current branch - `git branch -d `: Delete a branch ## Remote Repositories - `git remote add `: Add a remote repository (e.g., origin) - `git push `: Push changes to a remote branch - `git pull `: Pull changes from a remote branch - `git fetch`: Fetch changes from remote without merging ## Inspection and Comparison - `git log`: Show commit history - `git log --oneline`: Show commit history in one line per commit - `git diff`: Show changes between commits, commit and working tree, etc. - `git show `: Show details of a commit ## Undoing Changes - `git reset --hard`: Reset to the last commit, discarding changes - `git revert `: Create a new commit that undoes a previous commit - `git checkout -- `: Discard changes in a file ## Stashing - `git stash`: Stash changes in a dirty working directory - `git stash apply`: Apply stashed changes - `git stash list`: List stashed changes For more details, refer to the official Git documentation: https://git-scm.com/docs