Post

Git Cheat Sheet

Helpful Git commands to reference as a cheat sheet

Git Cheat Sheet

Repository Management

CommandDescription
git initInitialize a new Git repository
git clone <url>Clone a remote repository
git statusShow the working tree status
git add <file>Add a file to the staging area
git commit -m <message>Commit changes to the repository
git pushPush changes to the remote repository
git pullPull changes from the remote repository
git fetchFetch changes from the remote repository
git merge <branch>Merge a branch into the current branch
git branchList all branches
git branch <branch>Create a new branch
git checkout <branch>Switch to a branch
git checkout -b <branch>Create and switch to a new branch
git branch -d <branch>Delete a branch
git logShow commit logs
git diffShow changes between commits
git blame <file>Show who changed each line in a file
git reflogShow a log of changes to HEAD
git reset --hard <commit>Reset the repository to a commit
git revert <commit>Revert a commit
git stashStash changes in the working directory
git stash popApply stashed changes to the working directory
git tag <tag>Create a tag for a commit

Configuration

CommandDescription
git config --global user.name <user>Set the user name for Git
git config --global user.email <email>Set the user email for Git
git config --global core.editor <editor>Set the default text editor for Git
git config --global color.ui autoEnable colored output for Git

Remote Repositories

CommandDescription
git remote add <repository> <url>Add a remote repository
git remote -vList remote repositories
git remote show <repository>Show information about a remote repository
git remote rename <repository> <new_repository>Rename a remote repository
git remote remove <repository>Remove a remote repository
This post is licensed under CC BY 4.0 by the author.