Avatar

Git Cheat Sheet

Oct 10, 2025

#Git #CLI

A quick reference for the most common Git commands.

Configuration

To set up your Git identity.

CommandDescription
git config --global user.name "Alex-wuhu"Set your name for all commits.
git config --global user.email "yanglongwei06@gmail.com"Set your email for all commits.
git config --listList all Git settings.
git initInitialize a new Git repository.
git clone <url>Clone an existing repository.
CommandDescription
git statusShow the status of your files.
git add <file>Stage a specific file.
git add .Stage all new and modified files.
git diffShow unstaged changes.
git diff --stagedShow staged changes.
git commit -m "Your message"Commit staged changes.
git commit --amendModify the last commit.

Branches

Working with branches.

CommandDescription
git branchList all local branches.

Remote Repositories

Interacting with remote repositories like GitHub.

CommandDescription
git remote -vList all remote repositories.
git remote add <alias> <url>Add a new remote repository.
git fetch <remote>Download changes from a remote.
git pullFetch and merge changes from the remote.
git push <remote> <branch>Push your commits to a remote branch.

History

Inspecting the commit history.

CommandDescription
git logShow the commit history.
git log --onelineShow a condensed commit history.
git show <commit-hash>Show details of a specific commit.
git blame <file>Show who last modified each line of a file.

Undoing Changes

Reverting and resetting changes.

CommandDescription
git reset <file>Unstage a file.
git reset --hard <commit-hash>(Use with caution) Reset to a specific commit, discarding all subsequent changes.
git revert <commit-hash>Create a new commit that undoes a previous commit.
git stashTemporarily save changes that are not ready to be committed.
git stash popApply the most recently stashed changes.

GitHub Release

Creating a release on GitHub using the gh CLI.

# Create a compressed archive
tar zcvf snp-release.tar.gz snp-release/

# Create a new release on GitHub
gh release create v5.19.0 snp-release.tar.gz --title "Release Title" --notes "Release notes"
>