Skip to main content

Git Cheats

Cheat sheet for Git commands.

info

This page was automatically generated from a navi cheat file available at difranca/navi-cheats.
Navi is an interactive cheatsheet tool for the command-line. To learn more about it, visit denisidoro/navi.


Configโ€‹

Configure Git across all local repositories.

CommandDescription
git config --global user.name {name}Set global Git user name
git config --global user.email {email}Set global Git user email
git config --global color.ui autoSet automatic Git CLI coloring

Setupโ€‹

Initialize and clone repositories.

CommandDescription
git initInitialize a Git repository
git clone {repository}Clone a Git repository default branch to current directory
git clone -b {branch_name} {repository} {clone_directory}Clone a Git repository branch
git rev-parse --show-toplevelGet local repository top level directory

Stage & Changesโ€‹

Work with stage and unstaged changes.

CommandDescription
git statusShow modified and staged files
git add .Stage all files
git add {file}Stage a file
git reset {file}Unstage a file
git reset .Unstage all files
git diffShow diff of unstaged files
git diff --stagedShow diff of staged files
git commit -m {message}Commit staged changes
git commit --date="{date}" -m "{message}"Commit staged changes modifying the author date

Branchโ€‹

Work with branches

CommandDescription
git branchList branches
git branch {name}Create a new branch at the current commit
git checkout {branch}Switch to another branch

Log & Compareโ€‹

View logs and diffs in branches.

CommandDescription
git logShow commit history for active branch
git log {branch}..{second_branch}Show commits on first branch that are not on the second one
git log --follow {file}Show the commits that changed a file
git show {commit_sha}Show a commit object details

Updateโ€‹

Retrieve updates from repositories and push changes.

CommandDescription
git remote -vView all remote for a Git repository
git remote add {name} {url}Add a remote for a Git repository
git remote rename {remote_name} {new_name}Renames a remote for a Git repository
git remote remove {remote_name}Remove a remote for a git repository
git fetch {remote_name}Fetch all branches from Git remote
git pullPull commits from remote
git merge {branch}Merge specified branch into current branch
git merge --abortRollback to pre-merge state
git pushPush active branch commits to remote
git push -u {remote_name} {current_branch}Push local branch commits that does not have upstream to remote
git push {remote_name} {current_branch}:{branch}Push local branch commits to another branch

Rewriteโ€‹

Rewrite commits history.

CommandDescription
git rebase {branch}Apply commits from specified branch ahead of current branch
git reset --hard HEAD~{number_of_commits}Reset commits going back to a number of commits before HEAD (destroy changes)
git reset --soft HEAD~{number_of_commits}Reset commits going back to a number of commits before HEAD (keep changes)
git reset --hard {commit_sha}Reset commits going back to a specific commit (destroy changes)
git reset --soft {commit_sha}Reset commits going back to a specific commit (keep changes)

Temporaryโ€‹

Temporarily store modified files

CommandDescription
git stashSave modifications for later use and rollback to last the last commit
git stash listList saved stashes
git stash popApply stashed changes into the current branch (discard saved stash)
git stash applyApply stashed changes into the current branch (keep saved stash)
git stash dropDiscard saved stash

GitHubโ€‹

GitHub useful queries.

CommandDescription
https://github.com/pulls?&q=author:\{user\}+is:open+is:prSee all open pull requests of a user on Github