GIT Cheat Sheet : Commonly Used Commands


a comprehensive Git cheat sheet with many of the commonly used Git commands in table format:

commands in table format:

CommandDescription
git initInitialize a new Git repository in the current directory
git clone <url>Clone an existing Git repository located at <url> to your local machine
git add <filename>Add a file or changes to a file to the staging area
git add .Add all changed files to the staging area
git commit -m "<message>"Commit changes to the repository with a message describing the changes
git commit -aAdd all changed files and commit with a message
git statusShow the status of the current working directory
git diffShow the differences between the working directory and the staging area
git diff --cachedShow the differences between the staging area and the last commit
git logShow the commit history for the repository
git log --onelineShow the commit history in a condensed format
git log --graphShow the commit history as a graph
git branchList all local branches in the repository
git branch <branchname>Create a new branch with the specified name
git branch -d <branchname>Delete the branch with the specified name
git checkout <branchname>Switch to the specified branch
git checkout -b <branchname>Create and switch to a new branch with the specified name
git merge <branchname>Merge changes from the specified branch into the current branch
git remoteList all remote repositories
git remote add <name> <url>Add a new remote repository with the specified name and URL
git push <remotename> <localbranch>:<remotebranch>Push committed changes from the specified local branch to the specified remote branch
git pull <remotename> <remotebranch>Pull changes from the specified remote branch to the current local branch
git stashStash changes in the working directory for later use
git stash listList all stashes
git stash applyApply the most recent stash
git stash apply <stashname>Apply the stash with the specified name
git stash dropDiscard the most recent stash
git stash drop <stashname>Discard the stash with the specified name
git tagList all tags in the repository
git tag <tagname>Create a new tag with the specified name at the current commit
git tag -a <tagname> -m "<message>"Create a new annotated tag with the specified name and message at the current commit
git tag -d <tagname>Delete the tag with the specified name
git show <commit>Show information about the specified commit
git reset <commit>Reset the repository to the specified commit
git reset --hard <commit>Reset the repository to the specified commit and discard all changes
git clean -fRemove all untracked files from the working directory
git clean -f <directory>Remove all untracked files from the specified directory