This Git cheat sheet is your ultimate guide to refer to when you cannot remember a command or when you need some help!
Keep this resource bookmarked for the future. Let’s begin.
Git Cheat Sheet 101
Installation & GUIs
- Install Git (Linux):
sudo apt-get install git # Debian/Ubuntu
- Install Git (macOS):
brew install git
- Install Git (Windows):
Download the installer from: https://git-scm.com/download/win
Follow the installation steps in the wizard.
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
- GitHub Desktop
Download and install: https://desktop.github.com/
- Sourcetree
Download and install: https://www.sourcetreeapp.com/
- GitKraken
Download and install: https://www.gitkraken.com/
- Git GUI (built-in):
git gui
- Git Extensions
Download and install: https://gitextensions.github.io/
Setup Commands
- Set global username:
git config –global user.name “Your Name”
- Set global email:
git config –global user.email “[email protected]”
- Set default text editor for Git:
git config –global core.editor “nano” # or vim, code, etc.
- Check the current configuration:
git config –list
- Enable Git to remember your credentials (for HTTPS repos):
git config –global credential.helper cache

- Set up SSH key for Git (GitHub example):
- Generate SSH key:
ssh-keygen -t rsa -b 4096 -C “[email protected]”
- Add SSH key to the SSH agent:
eval “$(ssh-agent -s)”
ssh-add ~/.ssh/id_rsa
- Add SSH key to GitHub/GitLab/Bitbucket.
- Clone a repository with SSH:
git clone [email protected]:username/repository-name.git
- Change default branch name (from master to main):
git config –global init.defaultBranch main
Working with Repositories
- Create a new repository:
git init
- Clone an existing repository:
git clone <repository-url>
- List remote repositories:
git remote -v
- Add a new remote:
git remote add origin <url>
- Remove a remote:
git remote remove <name>
Making Changes
- Check repository status:
git status
- Add changes to staging area:
git add <file>
git add .
- Commit changes:
git commit -m “commit message”
- Add and commit in one step:
git commit -am “commit message”
- View commit history:
git log
- View condensed commit history:
git log –oneline
Related Article: Vim Cheat Sheet: Essential Commands for Efficient Editing
Remote Repositories
- Add a remote repository:
git remote add origin <url>
- View remote repositories:
git remote -v
- Push changes to remote:
git push origin <branch-name>
- Push and set upstream branch:
git push -u origin <branch-name>
- Pull changes from remote:
git pull origin <branch-name>
- Fetch changes without merging:
git fetch
- Difference between fetch and pull:
- git fetch: Downloads changes but does not merge.
- git pull: Downloads and merges changes automatically.
Undoing Changes
- Unstage a file (remove from staging area):
git reset HEAD <file>
- Discard changes in a file:
git checkout — <file>
- Amend the last commit (edit message or add changes):
git commit –amend
- Revert a specific commit (creates a new commit to undo):
git revert <commit-id>
- Reset to a previous commit (destructive!):
git reset –hard <commit-id>
- Soft reset (keep changes staged):
git reset –soft <commit-id>
- Mixed reset (unstage changes, keep working directory):
git reset –mixed <commit-id>
Stashing
- Save work-in-progress (stash changes):
git stash
- Save changes with a custom message:
git stash save “your message”
- List all stashes:
git stash list
- Apply the latest stash:
git stash apply
- Apply a specific stash:
git stash apply stash@{n}
- Drop the latest stash:
git stash drop
- Drop a specific stash:
git stash drop stash@{n}
- Apply and remove the latest stash (shortcut):
git stash pop
- Clear all stashes:
git stash clear
Tagging
- Create a lightweight tag:
git tag <tag-name>
- Create an annotated tag (recommended):
git tag -a <tag-name> -m “tag message”
- List all tags:
git tag
- View tag details:
git show <tag-name>
- Delete a local tag:
git tag -d <tag-name>
- Delete a remote tag:
git push –delete origin <tag-name>
- Push all tags to remote:
git push origin –tags
Common Log Commands
- View the commit history:
git log
- View a simplified commit history (one line per commit):
git log –oneline
- View commit history with a graphical representation:
git log –oneline –graph –all
- View commits by author:
git log –author=”Author Name”
- View commits in a specific date range:
git log –since=”2025-01-01″ –until=”2025-04-01″
- View changes made in each commit (patch):
git log -p
- Search commit messages for a keyword:
git log –grep=”keyword”
- Show a commit’s changes (diff) in the log:
git log -p <commit-id>
- Limit the number of log entries:
git log -n 10
General Git Commands
- Check Git configuration:
git config –list
- Set global username:
git config –global user.name “Your Name”
- Set global email:
git config –global user.email “[email protected]”
- Check the current branch:
git branch
- Rename the current branch:
git branch -m <new-branch-name>
- Delete a local branch:
git branch -d <branch-name>
- Show changes between commits (diff):
git diff <commit-id1> <commit-id2>
- Check the current repository’s URL:
git remote show origin
- Clone a repository with depth (shallow clone):
git clone –depth 1 <repository-url>
- Check if your branch is up to date with remote:
git fetch
git status
- Show the difference between staged and unstaged changes:
git diff –staged
Temporary Commits
- Create a temporary commit (stash changes without committing):
git commit –amend –no-edit
- Create a temporary commit with a message (for work-in-progress):
git commit -am “WIP: message”
- Stash changes temporarily:
git stash
- Apply the latest stash:
git stash apply
- Apply and remove the latest stash:
git stash pop
- Create a temporary branch for WIP:
git checkout -b temp-branch
- Switch back to the main branch after temp commit:
git checkout main
- Delete the temporary branch after merging changes:
git branch -d temp-branch
Wrapping Up – Git Cheat Sheet
Git cheat sheet is an essential tool for ease. Keep this cheat sheet at your disposal for ease and refer to it whenever you are stuck!
Can I use Git without GitHub?
Yes, Git can be used locally or with other platforms like GitLab, Bitbucket, or a private server. GitHub is just one of many Git repository hosts.
How can I resolve merge conflicts in Git?
Merge conflicts occur when changes overlap. Git will mark the conflict in the file—manually edit it, then use git add
and git commit
to resolve it.
How do I undo changes in Git?
You can use git restore
or git checkout
to undo changes in files, and git reset
to unstage or revert commits.