A Git cheat sheet

This page contains a list of Git commands that I know easily but are hard to remember

Push in a series of commits and rewrite the history by writing them as one

git rebase -i

This will put you into an interactive basic adjustment tool.

Types ofsApplicationsquashSubmit with the previous one. repeatsThe number of submissions required for the command.

Make a commit located in a separate branch and apply the same changes on the current branch

Single submission:

git cherry-pick <commit>

For multiple submissions:

git cherry-pick <commit1> <commit2> <commit3>

Restore the state of the file to the last commit (revert changes)

git checkout -- <filename>

Beautiful graph showing submission history

git log --pretty=format:"%h %s" --graph

Get more beautiful logs

git log --pretty=format:"%h - %an, %ar : %s"

Get a shorter state

git status -s

Pull request at local checkout

git fetch origin pull/<id>/head:<branch>

git checkout <branch>

List submissions involving specific documents

git log --follow -- <filename>

List submissions involving specific documents, including submissions

git log --follow -p -- <filename>

List repository contributors sorted by number of commits

git shortlog -s -n

Undo the last commit you pushed to the remote

git revert -n HEAD

Select all the changes you haven’t committed, and create a new branch

git checkout -b <branch>

Stop tracking files, but keep them in the file system

git rm -r --cached

Get the name of the branch that made a specific commit

git branch --contains <commit>


More git tutorials: