Git Commands - Cheat Sheet
git versionChecks installed Git version.
git config --global user.name "[name]"Sets your identity for all commits.
git config --global user.email "[email]"Sets commit email address.
git config --listLists all applied configuration settings.
git initInitializes a new, empty local Git repository.
git clone [url]Downloads a repository from a remote server.
git config --list to verify all settings are applied correctly.git statusShows which files are modified, staged, or untracked.
git add [file]Adds a specific file to the staging area.
git add .Adds all changed files in the directory to staging.
git add -p"Patch" mode: Stage parts of a file interactively.
git commit -m "[message]"Records the snapshot with a message.
git commit --amendModifies the last commit to fix typos or add files.
git branchLists all local branches in the repository.
git branch [name]Creates a new branch.
git checkout [branch-name]Switches to a specified branch.
git switch [branch-name]Modern alternative to switch branches.
git checkout -b [name]Create and switch to a branch immediately.
git merge [branch]Merges specified branch into the current one.
git branch -d [name]Deletes a branch safely.
git switch is the modern replacement for switching branches.-d) prevents deleting work that hasn't been merged.git remote -vLists all linked remote repositories.
git remote add origin [url]Connects your local repo to a remote server.
git fetchDownloads changes from remote without merging.
git pullDownloads changes and immediately merges them.
git push origin [branch]Uploads your commits to the remote branch.
git pull combines fetch and merge.git log --oneline --graphVisual history graph of all branches.
git diffShows differences between working dir and staging.
git diff --stagedShows differences between staging and last commit.
git blame [file]Shows who modified each line and when.
git show [id]Shows metadata and changes for a specific commit.
git log is your primary tool for tracking project evolution.git diff helps verify code before staging or committing.git stashTemporarily save uncommitted changes.
git stash popRestore and remove the most recent stash.
git reset --soft HEAD~1Undo commit but keep changes in staging.
git reset --hard HEAD~1Undo commit and delete all changes permanently.
git revert [id]Undo a commit by creating a new inverse commit.
git restore [file]Discard local changes to a specific file.
Categories: : AWS, AWS Certified Cloud Practitioner, Certification, Cheatsheet, DevOps, GitHub, Version Control